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