@@ -292,7 +292,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
292292 private val nullType = ConstantType (Constant (null ))
293293 private val nullSpace = Typ (nullType)
294294
295- override def intersectUnrelatedAtomicTypes (tp1 : Type , tp2 : Type ) = {
295+ override def intersectUnrelatedAtomicTypes (tp1 : Type , tp2 : Type ): Space = {
296296 val and = AndType (tp1, tp2)
297297 // Precondition: !(tp1 <:< tp2) && !(tp2 <:< tp1)
298298 // Then, no leaf of the and-type tree `and` is a subtype of `and`.
@@ -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,18 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
681681 }
682682 }
683683
684- val force = new ForceDegree .Value (
685- tvar => ! (ctx.typerState.constraint.entry(tvar.origin) eq tvar.origin.underlying),
686- minimizeAll = false
687- )
688-
684+ val removeThisType = new RemoveThisMap
689685 val tvars = tp1.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds) }
690686 val protoTp1 = removeThisType.apply(tp1).appliedTo(tvars)
691687
688+ val force = new ForceDegree .Value (
689+ tvar =>
690+ ! (ctx.typerState.constraint.entry(tvar.origin) `eq` tvar.origin.underlying) ||
691+ (tvar `eq` removeThisType.prefixTVar),
692+ minimizeAll = false ,
693+ allowBottom = false
694+ )
695+
692696 // If parent contains a reference to an abstract type, then we should
693697 // refine subtype checking to eliminate abstract types according to
694698 // variance. As this logic is only needed in exhaustivity check,
0 commit comments