Skip to content

Commit ca72e16

Browse files
committed
Remove tvars introduced while testing normalizedCompatible
1 parent 2fc299b commit ca72e16

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

compiler/src/dotty/tools/dotc/core/TyperState.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,15 @@ class TyperState() {
139139
def uncommittedAncestor: TyperState =
140140
if (isCommitted && previous != null) previous.uncheckedNN.uncommittedAncestor else this
141141

142-
/** Commit typer state so that its information is copied into current typer state
142+
/** Commit `this` typer state by copying information into the current typer state,
143+
* where "current" means contextual, so meaning `ctx.typerState`.
143144
* In addition (1) the owning state of undetermined or temporarily instantiated
144145
* type variables changes from this typer state to the current one. (2) Variables
145146
* that were temporarily instantiated in the current typer state are permanently
146147
* instantiated instead.
147148
*
148149
* A note on merging: An interesting test case is isApplicableSafe.scala. It turns out that this
149-
* requires a context merge using the new `&' operator. Sequence of actions:
150+
* requires a context merge using the new `&` operator. Sequence of actions:
150151
* 1) Typecheck argument in typerstate 1.
151152
* 2) Cache argument.
152153
* 3) Evolve same typer state (to typecheck other arguments, say)

compiler/src/dotty/tools/dotc/core/Types.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -4879,7 +4879,7 @@ object Types extends TypeUtils {
48794879
def origin: TypeParamRef = currentOrigin
48804880

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

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ 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-
newctx.typerState.commit()
74+
newctx.typerState.gc() // Remove any type lambdas and tvars added via testCompat
75+
newctx.typerState.commit() // Commit the rest of the typer state information
7576
result
7677
case _ => testCompat
7778
else explore(testCompat)
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

+15
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)