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 Oct 18, 2024
1 parent 2fc299b commit ca72e16
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TyperState.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,15 @@ class TyperState() {
def uncommittedAncestor: TyperState =
if (isCommitted && previous != null) previous.uncheckedNN.uncommittedAncestor else this

/** Commit typer state so that its information is copied into current typer state
/** Commit `this` typer state by copying information into the current typer state,
* where "current" means contextual, so meaning `ctx.typerState`.
* In addition (1) the owning state of undetermined or temporarily instantiated
* type variables changes from this typer state to the current one. (2) Variables
* that were temporarily instantiated in the current typer state are permanently
* instantiated instead.
*
* A note on merging: An interesting test case is isApplicableSafe.scala. It turns out that this
* requires a context merge using the new `&' operator. Sequence of actions:
* requires a context merge using the new `&` operator. Sequence of actions:
* 1) Typecheck argument in typerstate 1.
* 2) Cache argument.
* 3) Evolve same typer state (to typecheck other arguments, say)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4879,7 +4879,7 @@ object Types extends TypeUtils {
def origin: TypeParamRef = currentOrigin

/** Set origin to new parameter. Called if we merge two conflicting constraints.
* See OrderingConstraint#merge, OrderingConstraint#rename
* See OrderingConstraint#merge
*/
def setOrigin(p: TypeParamRef) = currentOrigin = p

Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ object ProtoTypes {
|constraint was: ${ctx.typerState.constraint}
|constraint now: ${newctx.typerState.constraint}""")
if result && (ctx.typerState.constraint ne newctx.typerState.constraint) then
newctx.typerState.commit()
newctx.typerState.gc() // Remove any type lambdas and tvars added via testCompat
newctx.typerState.commit() // Commit the rest of the typer state information
result
case _ => testCompat
else explore(testCompat)
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 ca72e16

Please sign in to comment.