@@ -139,7 +139,7 @@ object Types extends TypeUtils {
139
139
case t : AppliedType =>
140
140
t.fold(false , (x, tp) => x || test(tp, theAcc))
141
141
case t : TypeVar =>
142
- ! t.inst.exists || test(t.inst , theAcc)
142
+ ! t.isPermanentlyInstantiated || test(t.permanentInst , theAcc)
143
143
case t : LazyRef =>
144
144
! t.completed || test(t.ref, theAcc)
145
145
case _ =>
@@ -4934,20 +4934,24 @@ object Types extends TypeUtils {
4934
4934
def setOrigin (p : TypeParamRef ) = currentOrigin = p
4935
4935
4936
4936
/** The permanent instance type of the variable, or NoType is none is given yet */
4937
- private var myInst : Type = NoType
4937
+ private var inst : Type = NoType
4938
4938
4939
- private [core] def inst : Type = myInst
4940
- private [core] def setInst (tp : Type ): Unit =
4941
- myInst = tp
4939
+ /** The permanent instance type that's stored in the type variable, so it cannot be retracted
4940
+ * anymore, or NoType if the variable can still be further constrained or a provisional
4941
+ * instance type in the constraint can be retracted.
4942
+ */
4943
+ private [core] def permanentInst = inst
4944
+ private [core] def setPermanentInst (tp : Type ): Unit =
4945
+ inst = tp
4942
4946
if tp.exists && owningState != null then
4943
4947
val owningState1 = owningState.uncheckedNN.get
4944
4948
if owningState1 != null then
4945
4949
owningState1.ownedVars -= this
4946
4950
owningState = null // no longer needed; null out to avoid a memory leak
4947
4951
4948
4952
private [core] def resetInst (ts : TyperState ): Unit =
4949
- assert(myInst .exists)
4950
- myInst = NoType
4953
+ assert(inst .exists)
4954
+ inst = NoType
4951
4955
owningState = new WeakReference (ts)
4952
4956
4953
4957
/** The state owning the variable. This is at first `creatorState`, but it can
@@ -4985,18 +4989,23 @@ object Types extends TypeUtils {
4985
4989
/** Is the variable already instantiated? */
4986
4990
def isInstantiated (using Context ): Boolean = instanceOpt.exists
4987
4991
4992
+ /** Is the variable already instantiated so that the instance cannot be
4993
+ * retracted anymore?
4994
+ */
4995
+ def isPermanentlyInstantiated : Boolean = inst.exists
4996
+
4988
4997
/** Instantiate variable with given type */
4989
4998
def instantiateWith (tp : Type )(using Context ): Type = {
4990
4999
assert(tp ne this , i " self instantiation of $origin, constraint = ${ctx.typerState.constraint}" )
4991
- assert(! myInst .exists, i " $origin is already instantiated to $myInst but we attempted to instantiate it to $tp" )
5000
+ assert(! inst .exists, i " $origin is already instantiated to $inst but we attempted to instantiate it to $tp" )
4992
5001
typr.println(i " instantiating $this with $tp" )
4993
5002
4994
5003
if Config .checkConstraintsSatisfiable then
4995
5004
assert(currentEntry.bounds.contains(tp),
4996
5005
i " $origin is constrained to be $currentEntry but attempted to instantiate it to $tp" )
4997
5006
4998
5007
if ((ctx.typerState eq owningState.nn.get.uncheckedNN) && ! TypeComparer .subtypeCheckInProgress)
4999
- setInst (tp)
5008
+ setPermanentInst (tp)
5000
5009
ctx.typerState.constraint = ctx.typerState.constraint.replace(origin, tp)
5001
5010
tp
5002
5011
}
@@ -5013,8 +5022,8 @@ object Types extends TypeUtils {
5013
5022
*/
5014
5023
def instantiate (fromBelow : Boolean )(using Context ): Type =
5015
5024
val tp = typeToInstantiateWith(fromBelow)
5016
- if myInst .exists then // The line above might have triggered instantiation of the current type variable
5017
- myInst
5025
+ if inst .exists then // The line above might have triggered instantiation of the current type variable
5026
+ inst
5018
5027
else
5019
5028
instantiateWith(tp)
5020
5029
0 commit comments