@@ -137,7 +137,7 @@ object Types extends TypeUtils {
137
137
case t : AppliedType =>
138
138
t.fold(false , (x, tp) => x || test(tp, theAcc))
139
139
case t : TypeVar =>
140
- ! t.inst.exists || test(t.inst , theAcc)
140
+ ! t.isPermanentlyInstantiated || test(t.permanentInst , theAcc)
141
141
case t : LazyRef =>
142
142
! t.completed || test(t.ref, theAcc)
143
143
case _ =>
@@ -4792,20 +4792,24 @@ object Types extends TypeUtils {
4792
4792
def setOrigin (p : TypeParamRef ) = currentOrigin = p
4793
4793
4794
4794
/** The permanent instance type of the variable, or NoType is none is given yet */
4795
- private var myInst : Type = NoType
4795
+ private var inst : Type = NoType
4796
4796
4797
- private [core] def inst : Type = myInst
4798
- private [core] def setInst (tp : Type ): Unit =
4799
- myInst = tp
4797
+ /** The permanent instance type that's stored in the type variable, so it cannot be retracted
4798
+ * anymore, or NoType if the variable can still be further constrained or a provisional
4799
+ * instance type in the constraint can be retracted.
4800
+ */
4801
+ private [core] def permanentInst = inst
4802
+ private [core] def setPermanentInst (tp : Type ): Unit =
4803
+ inst = tp
4800
4804
if tp.exists && owningState != null then
4801
4805
val owningState1 = owningState.uncheckedNN.get
4802
4806
if owningState1 != null then
4803
4807
owningState1.ownedVars -= this
4804
4808
owningState = null // no longer needed; null out to avoid a memory leak
4805
4809
4806
4810
private [core] def resetInst (ts : TyperState ): Unit =
4807
- assert(myInst .exists)
4808
- myInst = NoType
4811
+ assert(inst .exists)
4812
+ inst = NoType
4809
4813
owningState = new WeakReference (ts)
4810
4814
4811
4815
/** The state owning the variable. This is at first `creatorState`, but it can
@@ -4843,18 +4847,23 @@ object Types extends TypeUtils {
4843
4847
/** Is the variable already instantiated? */
4844
4848
def isInstantiated (using Context ): Boolean = instanceOpt.exists
4845
4849
4850
+ /** Is the variable already instantiated so that the instance cannot be
4851
+ * retracted anymore?
4852
+ */
4853
+ def isPermanentlyInstantiated : Boolean = inst.exists
4854
+
4846
4855
/** Instantiate variable with given type */
4847
4856
def instantiateWith (tp : Type )(using Context ): Type = {
4848
4857
assert(tp ne this , i " self instantiation of $origin, constraint = ${ctx.typerState.constraint}" )
4849
- assert(! myInst .exists, i " $origin is already instantiated to $myInst but we attempted to instantiate it to $tp" )
4858
+ assert(! inst .exists, i " $origin is already instantiated to $inst but we attempted to instantiate it to $tp" )
4850
4859
typr.println(i " instantiating $this with $tp" )
4851
4860
4852
4861
if Config .checkConstraintsSatisfiable then
4853
4862
assert(currentEntry.bounds.contains(tp),
4854
4863
i " $origin is constrained to be $currentEntry but attempted to instantiate it to $tp" )
4855
4864
4856
4865
if ((ctx.typerState eq owningState.nn.get.uncheckedNN) && ! TypeComparer .subtypeCheckInProgress)
4857
- setInst (tp)
4866
+ setPermanentInst (tp)
4858
4867
ctx.typerState.constraint = ctx.typerState.constraint.replace(origin, tp)
4859
4868
tp
4860
4869
}
@@ -4868,8 +4877,8 @@ object Types extends TypeUtils {
4868
4877
*/
4869
4878
def instantiate (fromBelow : Boolean )(using Context ): Type =
4870
4879
val tp = TypeComparer .instanceType(origin, fromBelow, widenUnions, nestingLevel)
4871
- if myInst .exists then // The line above might have triggered instantiation of the current type variable
4872
- myInst
4880
+ if inst .exists then // The line above might have triggered instantiation of the current type variable
4881
+ inst
4873
4882
else
4874
4883
instantiateWith(tp)
4875
4884
0 commit comments