Skip to content

Commit 820c0ca

Browse files
committed
Remove tvars introduced while testing normalizedCompatible
1 parent 5101daf commit 820c0ca

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ object ProtoTypes {
7171
|constraint was: ${ctx.typerState.constraint}
7272
|constraint now: ${newctx.typerState.constraint}""")
7373
if result && (ctx.typerState.constraint ne newctx.typerState.constraint) then
74+
val tvars = (newctx.typerState.ownedVars -- ctx.typerState.ownedVars).toList
75+
inContext(newctx):
76+
Inferencing.instantiateSelected(tp, tvars)
77+
for tvar <- tvars do if !tvar.isInstantiated then tvar.instantiate(fromBelow = false)
7478
newctx.typerState.commit()
7579
result
7680
case _ => testCompat

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3557,6 +3557,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
35573557
protected def simplify(tree: Tree, pt: Type, locked: TypeVars)(using Context): tree.type =
35583558
if !tree.denot.isOverloaded then // for overloaded trees: resolve overloading before simplifying
35593559
if !tree.tpe.widen.isInstanceOf[MethodOrPoly] // wait with simplifying until method is fully applied
3560+
&& !tree.tpe.match { case defn.PolyFunctionOf(_) => true case _ => false } // ... or polyfunction is fully applied
35603561
|| tree.isDef // ... unless tree is a definition
35613562
then
35623563
interpolateTypeVars(tree, pt, locked)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Justifies the need to add defn.PolyFunctionOf in simplify
2+
// Without, the TypeVar for the U in fn's lambda
3+
// replaces the TypeParamRef U, in simplify.
4+
class B[U]
5+
class Test():
6+
def fn[T]: [U] => Int => B[U] = [U] => (x: Int) => new B[U]()
7+
def test(): Unit =
8+
fn(1)
9+
fn(2)
10+
()

tests/pos/zipped.min.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Justifies the need for TypeApply in tryInsertImplicitOnQualifier
2+
// after failing ys.map[?B, C] using Zipped2's map
3+
// we want to try ys.map[?B] using Coll's map, after toColl
4+
final class Coll[+A]:
5+
def map[B](f: A => B): Coll[B] = new Coll[B]
6+
def lazyZip[B](that: Coll[B]): Zipped2[A, B] = new Zipped2[A, B](this, that)
7+
final class Zipped2[+X, +Y](xs: Coll[X], ys: Coll[Y]):
8+
def map[B, C](f: (X, Y) => B): Coll[C] = new Coll[C]
9+
object Zipped2:
10+
import scala.language.implicitConversions
11+
implicit def toColl[X, Y](zipped2: Zipped2[X, Y]): Coll[(X, Y)] = new Coll[(X, Y)]
12+
class Test:
13+
def test(xs: Coll[Int]): Unit =
14+
val ys = xs.lazyZip(xs)
15+
ys.map((x: (Int, Int)) => x._1 + x._2)

0 commit comments

Comments
 (0)