@@ -137,7 +137,7 @@ object Types extends TypeUtils {
137137 case t : AppliedType =>
138138 t.fold(false , (x, tp) => x || test(tp, theAcc))
139139 case t : TypeVar =>
140- ! t.inst.exists || test(t.inst , theAcc)
140+ ! t.isPermanentlyInstantiated || test(t.permanentInst , theAcc)
141141 case t : LazyRef =>
142142 ! t.completed || test(t.ref, theAcc)
143143 case _ =>
@@ -4792,20 +4792,24 @@ object Types extends TypeUtils {
47924792 def setOrigin (p : TypeParamRef ) = currentOrigin = p
47934793
47944794 /** 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
47964796
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
48004804 if tp.exists && owningState != null then
48014805 val owningState1 = owningState.uncheckedNN.get
48024806 if owningState1 != null then
48034807 owningState1.ownedVars -= this
48044808 owningState = null // no longer needed; null out to avoid a memory leak
48054809
48064810 private [core] def resetInst (ts : TyperState ): Unit =
4807- assert(myInst .exists)
4808- myInst = NoType
4811+ assert(inst .exists)
4812+ inst = NoType
48094813 owningState = new WeakReference (ts)
48104814
48114815 /** The state owning the variable. This is at first `creatorState`, but it can
@@ -4843,18 +4847,23 @@ object Types extends TypeUtils {
48434847 /** Is the variable already instantiated? */
48444848 def isInstantiated (using Context ): Boolean = instanceOpt.exists
48454849
4850+ /** Is the variable already instantiated so that the instance cannot be
4851+ * retracted anymore?
4852+ */
4853+ def isPermanentlyInstantiated : Boolean = inst.exists
4854+
48464855 /** Instantiate variable with given type */
48474856 def instantiateWith (tp : Type )(using Context ): Type = {
48484857 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" )
48504859 typr.println(i " instantiating $this with $tp" )
48514860
48524861 if Config .checkConstraintsSatisfiable then
48534862 assert(currentEntry.bounds.contains(tp),
48544863 i " $origin is constrained to be $currentEntry but attempted to instantiate it to $tp" )
48554864
48564865 if ((ctx.typerState eq owningState.nn.get.uncheckedNN) && ! TypeComparer .subtypeCheckInProgress)
4857- setInst (tp)
4866+ setPermanentInst (tp)
48584867 ctx.typerState.constraint = ctx.typerState.constraint.replace(origin, tp)
48594868 tp
48604869 }
@@ -4868,8 +4877,8 @@ object Types extends TypeUtils {
48684877 */
48694878 def instantiate (fromBelow : Boolean )(using Context ): Type =
48704879 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
48734882 else
48744883 instantiateWith(tp)
48754884
0 commit comments