@@ -4919,20 +4919,21 @@ object Types extends TypeUtils {
4919
4919
def isInstantiated (using Context ): Boolean = instanceOpt.exists
4920
4920
4921
4921
/** Instantiate variable with given type */
4922
- def instantiateWith (tp : Type )(using Context ): Type = {
4923
- assert(tp ne this , i " self instantiation of $origin, constraint = ${ctx.typerState.constraint}" )
4924
- assert(! myInst.exists, i " $origin is already instantiated to $myInst but we attempted to instantiate it to $tp" )
4925
- typr.println(i " instantiating $this with $tp" )
4922
+ def instantiateWith (tp : Type )(using Context ): Type =
4923
+ if myInst.exists then myInst
4924
+ else
4925
+ assert(tp ne this , i " self instantiation of $origin, constraint = ${ctx.typerState.constraint}" )
4926
+ assert(! myInst.exists, i " $origin is already instantiated to $myInst but we attempted to instantiate it to $tp" )
4927
+ typr.println(i " instantiating $this with $tp" )
4926
4928
4927
- if Config .checkConstraintsSatisfiable then
4928
- assert(currentEntry.bounds.contains(tp),
4929
- i " $origin is constrained to be $currentEntry but attempted to instantiate it to $tp" )
4929
+ if Config .checkConstraintsSatisfiable then
4930
+ assert(currentEntry.bounds.contains(tp),
4931
+ i " $origin is constrained to be $currentEntry but attempted to instantiate it to $tp" )
4930
4932
4931
- if ((ctx.typerState eq owningState.nn.get.uncheckedNN) && ! TypeComparer .subtypeCheckInProgress)
4932
- setInst(tp)
4933
- ctx.typerState.constraint = ctx.typerState.constraint.replace(origin, tp)
4934
- tp
4935
- }
4933
+ if ((ctx.typerState eq owningState.nn.get.uncheckedNN) && ! TypeComparer .subtypeCheckInProgress)
4934
+ setInst(tp)
4935
+ ctx.typerState.constraint = ctx.typerState.constraint.replace(origin, tp)
4936
+ tp
4936
4937
4937
4938
def typeToInstantiateWith (fromBelow : Boolean )(using Context ): Type =
4938
4939
TypeComparer .instanceType(origin, fromBelow, widenUnions, nestingLevel)
@@ -4946,10 +4947,7 @@ object Types extends TypeUtils {
4946
4947
*/
4947
4948
def instantiate (fromBelow : Boolean )(using Context ): Type =
4948
4949
val tp = typeToInstantiateWith(fromBelow)
4949
- if myInst.exists then // The line above might have triggered instantiation of the current type variable
4950
- myInst
4951
- else
4952
- instantiateWith(tp)
4950
+ instantiateWith(tp)
4953
4951
4954
4952
/** Widen unions when instantiating this variable in the current context? */
4955
4953
def widenUnions (using Context ): Boolean = ! ctx.typerState.constraint.isHard(this )
0 commit comments