Skip to content

Commit

Permalink
Remove tvars introduced while testing normalizedCompatible
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Aug 27, 2024
1 parent 5101daf commit 820c0ca
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ object ProtoTypes {
|constraint was: ${ctx.typerState.constraint}
|constraint now: ${newctx.typerState.constraint}""")
if result && (ctx.typerState.constraint ne newctx.typerState.constraint) then
val tvars = (newctx.typerState.ownedVars -- ctx.typerState.ownedVars).toList
inContext(newctx):
Inferencing.instantiateSelected(tp, tvars)
for tvar <- tvars do if !tvar.isInstantiated then tvar.instantiate(fromBelow = false)
newctx.typerState.commit()
result
case _ => testCompat
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3557,6 +3557,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
protected def simplify(tree: Tree, pt: Type, locked: TypeVars)(using Context): tree.type =
if !tree.denot.isOverloaded then // for overloaded trees: resolve overloading before simplifying
if !tree.tpe.widen.isInstanceOf[MethodOrPoly] // wait with simplifying until method is fully applied
&& !tree.tpe.match { case defn.PolyFunctionOf(_) => true case _ => false } // ... or polyfunction is fully applied
|| tree.isDef // ... unless tree is a definition
then
interpolateTypeVars(tree, pt, locked)
Expand Down
10 changes: 10 additions & 0 deletions tests/pos/interleaving-overload.cleanup.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Justifies the need to add defn.PolyFunctionOf in simplify
// Without, the TypeVar for the U in fn's lambda
// replaces the TypeParamRef U, in simplify.
class B[U]
class Test():
def fn[T]: [U] => Int => B[U] = [U] => (x: Int) => new B[U]()
def test(): Unit =
fn(1)
fn(2)
()
15 changes: 15 additions & 0 deletions tests/pos/zipped.min.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Justifies the need for TypeApply in tryInsertImplicitOnQualifier
// after failing ys.map[?B, C] using Zipped2's map
// we want to try ys.map[?B] using Coll's map, after toColl
final class Coll[+A]:
def map[B](f: A => B): Coll[B] = new Coll[B]
def lazyZip[B](that: Coll[B]): Zipped2[A, B] = new Zipped2[A, B](this, that)
final class Zipped2[+X, +Y](xs: Coll[X], ys: Coll[Y]):
def map[B, C](f: (X, Y) => B): Coll[C] = new Coll[C]
object Zipped2:
import scala.language.implicitConversions
implicit def toColl[X, Y](zipped2: Zipped2[X, Y]): Coll[(X, Y)] = new Coll[(X, Y)]
class Test:
def test(xs: Coll[Int]): Unit =
val ys = xs.lazyZip(xs)
ys.map((x: (Int, Int)) => x._1 + x._2)

0 comments on commit 820c0ca

Please sign in to comment.