@@ -656,18 +656,18 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
656656 // Fix subtype checking for child instantiation,
657657 // such that `Foo(Test.this.foo) <:< Foo(Foo.this)`
658658 // See tests/patmat/i3938.scala
659- def removeThisType (implicit ctx : Context ) = new TypeMap {
660- // is in tvarBounds? Don't create new tvars if true
661- private var tvarBounds : Boolean = false
659+ class RemoveThisMap extends TypeMap {
660+ var prefixTVar : Type = null
662661 def apply (tp : Type ): Type = tp match {
663662 case ThisType (tref : TypeRef ) if ! tref.symbol.isStaticOwner =>
664663 if (tref.symbol.is(Module ))
665664 TermRef (this (tref.prefix), tref.symbol.sourceModule)
666- else if (tvarBounds )
665+ else if (prefixTVar != null )
667666 this (tref)
668667 else {
669- tvarBounds = true
670- newTypeVar(TypeBounds .upper(this (tref)))
668+ prefixTVar = WildcardType // prevent recursive call from assigning it
669+ prefixTVar = newTypeVar(TypeBounds .upper(this (tref)))
670+ prefixTVar
671671 }
672672 case tp => mapOver(tp)
673673 }
@@ -681,14 +681,17 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
681681 }
682682 }
683683
684+ val removeThisType = new RemoveThisMap
685+ val tvars = tp1.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds) }
686+ val protoTp1 = removeThisType.apply(tp1).appliedTo(tvars)
687+
684688 val force = new ForceDegree .Value (
685- tvar => ! (ctx.typerState.constraint.entry(tvar.origin) eq tvar.origin.underlying),
689+ tvar =>
690+ ! (ctx.typerState.constraint.entry(tvar.origin) `eq` tvar.origin.underlying) ||
691+ (tvar `eq` removeThisType.prefixTVar),
686692 minimizeAll = false
687693 )
688694
689- val tvars = tp1.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds) }
690- val protoTp1 = removeThisType.apply(tp1).appliedTo(tvars)
691-
692695 // If parent contains a reference to an abstract type, then we should
693696 // refine subtype checking to eliminate abstract types according to
694697 // variance. As this logic is only needed in exhaustivity check,
0 commit comments