@@ -656,18 +656,18 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
656
656
// Fix subtype checking for child instantiation,
657
657
// such that `Foo(Test.this.foo) <:< Foo(Foo.this)`
658
658
// 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
662
661
def apply (tp : Type ): Type = tp match {
663
662
case ThisType (tref : TypeRef ) if ! tref.symbol.isStaticOwner =>
664
663
if (tref.symbol.is(Module ))
665
664
TermRef (this (tref.prefix), tref.symbol.sourceModule)
666
- else if (tvarBounds )
665
+ else if (prefixTVar != null )
667
666
this (tref)
668
667
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
671
671
}
672
672
case tp => mapOver(tp)
673
673
}
@@ -681,14 +681,17 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
681
681
}
682
682
}
683
683
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
+
684
688
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),
686
692
minimizeAll = false
687
693
)
688
694
689
- val tvars = tp1.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds) }
690
- val protoTp1 = removeThisType.apply(tp1).appliedTo(tvars)
691
-
692
695
// If parent contains a reference to an abstract type, then we should
693
696
// refine subtype checking to eliminate abstract types according to
694
697
// variance. As this logic is only needed in exhaustivity check,
0 commit comments