@@ -403,20 +403,21 @@ object Inferencing {
403403 val vs = variances(tp)
404404 val patternBindings = new mutable.ListBuffer [(Symbol , TypeParamRef )]
405405 vs foreachBinding { (tvar, v) =>
406- if (v == 1 ) tvar.instantiate(fromBelow = false )
407- else if (v == - 1 ) tvar.instantiate(fromBelow = true )
408- else {
409- val bounds = TypeComparer .fullBounds(tvar.origin)
410- if (bounds.hi <:< bounds.lo || bounds.hi.classSymbol.is(Final ) || fromScala2x)
411- tvar.instantiate(fromBelow = false )
406+ if ! tvar.isInstantiated then
407+ if (v == 1 ) tvar.instantiate(fromBelow = false )
408+ else if (v == - 1 ) tvar.instantiate(fromBelow = true )
412409 else {
413- // We do not add the created symbols to GADT constraint immediately, since they may have inter-dependencies.
414- // Instead, we simultaneously add them later on.
415- val wildCard = newPatternBoundSymbol(UniqueName .fresh(tvar.origin.paramName), bounds, span, addToGadt = false )
416- tvar.instantiateWith(wildCard.typeRef)
417- patternBindings += ((wildCard, tvar.origin))
410+ val bounds = TypeComparer .fullBounds(tvar.origin)
411+ if (bounds.hi <:< bounds.lo || bounds.hi.classSymbol.is(Final ) || fromScala2x)
412+ tvar.instantiate(fromBelow = false )
413+ else {
414+ // We do not add the created symbols to GADT constraint immediately, since they may have inter-dependencies.
415+ // Instead, we simultaneously add them later on.
416+ val wildCard = newPatternBoundSymbol(UniqueName .fresh(tvar.origin.paramName), bounds, span, addToGadt = false )
417+ tvar.instantiateWith(wildCard.typeRef)
418+ patternBindings += ((wildCard, tvar.origin))
419+ }
418420 }
419- }
420421 }
421422 val res = patternBindings.toList.map { (boundSym, _) =>
422423 // substitute bounds of pattern bound variables to deal with possible F-bounds
@@ -654,13 +655,16 @@ trait Inferencing { this: Typer =>
654655 while buf.nonEmpty do
655656 val first @ (tvar, fromBelow) = buf.head
656657 buf.dropInPlace(1 )
657- val suspend = buf.exists{ (following, _) =>
658- if fromBelow then
659- constraint.isLess(following.origin, tvar.origin)
660- else
661- constraint.isLess(tvar.origin, following.origin)
662- }
663- if suspend then suspended += first else tvar.instantiate(fromBelow)
658+ if ! tvar.isInstantiated then
659+ val suspend = buf.exists{ (following, _) =>
660+ if fromBelow then
661+ constraint.isLess(following.origin, tvar.origin)
662+ else
663+ constraint.isLess(tvar.origin, following.origin)
664+ }
665+ if suspend then suspended += first else tvar.instantiate(fromBelow)
666+ end if
667+ end while
664668 doInstantiate(suspended)
665669 end doInstantiate
666670 doInstantiate(toInstantiate)
0 commit comments