@@ -601,7 +601,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
601
601
def instantiate (tp1 : Type , tp2 : Type )(implicit ctx : Context ): Type = {
602
602
// map `ThisType` of `tp1` to a type variable
603
603
// precondition: `tp1` should have the shape `path.Child`, thus `ThisType` is always covariant
604
- val thisTypeMap = new TypeMap {
604
+ def childTypeMap ( implicit ctx : Context ) = new TypeMap {
605
605
def apply (t : Type ): Type = t.dealias match {
606
606
case tp @ ThisType (tref) if ! tref.symbol.isStaticOwner =>
607
607
if (tref.symbol.is(Module )) mapOver(tref)
@@ -623,7 +623,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
623
623
}
624
624
625
625
// replace type parameter references with bounds
626
- val typeParamMap = new TypeMap {
626
+ def parentTypeMap ( implicit ctx : Context ) = new TypeMap {
627
627
def apply (t : Type ): Type = t.dealias match {
628
628
case tp : TypeRef if tp.underlying.isInstanceOf [TypeBounds ] =>
629
629
// See tests/patmat/gadt.scala tests/patmat/exhausting.scala tests/patmat/t9657.scala
@@ -640,7 +640,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
640
640
}
641
641
642
642
// replace uninstantiated type vars with WildcardType, check tests/patmat/3333.scala
643
- val instUndetMap = new TypeMap {
643
+ def instUndetMap ( implicit ctx : Context ) = new TypeMap {
644
644
def apply (t : Type ): Type = t match {
645
645
case tvar : TypeVar if ! tvar.isInstantiated => WildcardType (tvar.origin.underlying.bounds)
646
646
case _ => mapOver(t)
@@ -653,27 +653,27 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
653
653
)
654
654
655
655
val tvars = tp1.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds) }
656
- val protoTp1 = thisTypeMap (tp1.appliedTo(tvars))
656
+ val protoTp1 = childTypeMap.apply (tp1.appliedTo(tvars))
657
657
658
658
// If parent contains a reference to an abstract type, then we should
659
659
// refine subtype checking to eliminate abstract types according to
660
660
// variance. As this logic is only needed in exhaustivity check, thus
661
661
// we manually patch subtyping check instead of changing TypeComparer.
662
662
// See tests/patmat/3645b.scala
663
663
def parentQualify = tp1.widen.classSymbol.info.parents.exists { parent =>
664
- (parent.argInfos.nonEmpty || parent.abstractTypeMembers.nonEmpty) &&
665
- instantiate (parent, tp2)(ctx.fresh.setNewTyperState()).exists
664
+ implicit val ictx = ctx.fresh.setNewTyperState()
665
+ parent.argInfos.nonEmpty && childTypeMap.apply (parent) <:< parentTypeMap.apply(tp2)
666
666
}
667
667
668
668
if (protoTp1 <:< tp2) {
669
669
if (isFullyDefined(protoTp1, force)) protoTp1
670
- else instUndetMap(protoTp1)
670
+ else instUndetMap.apply (protoTp1)
671
671
}
672
672
else {
673
- val protoTp2 = typeParamMap (tp2)
673
+ val protoTp2 = parentTypeMap.apply (tp2)
674
674
if (protoTp1 <:< protoTp2 || parentQualify) {
675
675
if (isFullyDefined(AndType (protoTp1, protoTp2), force)) protoTp1
676
- else instUndetMap(protoTp1)
676
+ else instUndetMap.apply (protoTp1)
677
677
}
678
678
else {
679
679
debug.println(s " $protoTp1 <:< $protoTp2 = false " )
0 commit comments