File tree 3 files changed +19
-3
lines changed
compiler/src/dotty/tools/dotc
3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,17 @@ object TyperState {
22
22
.init(null , OrderingConstraint .empty)
23
23
.setReporter(new ConsoleReporter ())
24
24
.setCommittable(true )
25
+
26
+ opaque type Snapshot = (Constraint , TypeVars )
27
+
28
+ extension (ts : TyperState )
29
+ def snapshot (): Snapshot = (ts.constraint, ts.ownedVars)
30
+
31
+ def resetTo (state : Snapshot )(using Context ): Unit =
32
+ val (c, tvs) = state
33
+ for tv <- tvs do if tv.isInstantiated then tv.resetInst(ts)
34
+ ts.ownedVars = tvs
35
+ ts.constraint = c
25
36
}
26
37
27
38
class TyperState () {
Original file line number Diff line number Diff line change @@ -4404,6 +4404,10 @@ object Types {
4404
4404
owningState1.ownedVars -= this
4405
4405
owningState = null // no longer needed; null out to avoid a memory leak
4406
4406
4407
+ private [core] def resetInst (ts : TyperState ): Unit =
4408
+ myInst = NoType
4409
+ owningState = new WeakReference (ts)
4410
+
4407
4411
/** The state owning the variable. This is at first `creatorState`, but it can
4408
4412
* be changed to an enclosing state on a commit.
4409
4413
*/
Original file line number Diff line number Diff line change @@ -3247,7 +3247,7 @@ class Typer extends Namer
3247
3247
replaceSingletons(tp)
3248
3248
}
3249
3249
wtp.paramInfos.foreach(instantiate)
3250
- val constr = ctx.typerState.constraint
3250
+ val saved = ctx.typerState.snapshot()
3251
3251
3252
3252
def dummyArg (tp : Type ) = untpd.Ident (nme.??? ).withTypeUnchecked(tp)
3253
3253
@@ -3347,8 +3347,9 @@ class Typer extends Namer
3347
3347
if (propFail.exists) {
3348
3348
// If there are several arguments, some arguments might already
3349
3349
// have influenced the context, binding variables, but later ones
3350
- // might fail. In that case the constraint needs to be reset.
3351
- ctx.typerState.constraint = constr
3350
+ // might fail. In that case the constraint and instantiated variables
3351
+ // need to be reset.
3352
+ ctx.typerState.resetTo(saved)
3352
3353
3353
3354
// If method has default params, fall back to regular application
3354
3355
// where all inferred implicits are passed as named args.
You can’t perform that action at this time.
0 commit comments