@@ -582,7 +582,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
582
582
def instantiate (tp1 : Type , tp2 : Type )(implicit ctx : Context ): Type = {
583
583
// map `ThisType` of `tp1` to a type variable
584
584
// precondition: `tp1` should have the shape `path.Child`, thus `ThisType` is always covariant
585
- val thisTypeMap = new TypeMap {
585
+ def childTypeMap ( implicit ctx : Context ) = new TypeMap {
586
586
def apply (t : Type ): Type = t.dealias match {
587
587
case tp @ ThisType (tref) if ! tref.symbol.isStaticOwner =>
588
588
if (tref.symbol.is(Module )) mapOver(tref)
@@ -604,7 +604,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
604
604
}
605
605
606
606
// replace type parameter references with bounds
607
- val typeParamMap = new TypeMap {
607
+ def parentTypeMap ( implicit ctx : Context ) = new TypeMap {
608
608
def apply (t : Type ): Type = t.dealias match {
609
609
case tp : TypeRef if tp.underlying.isInstanceOf [TypeBounds ] =>
610
610
// See tests/patmat/gadt.scala tests/patmat/exhausting.scala tests/patmat/t9657.scala
@@ -621,7 +621,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
621
621
}
622
622
623
623
// replace uninstantiated type vars with WildcardType, check tests/patmat/3333.scala
624
- val instUndetMap = new TypeMap {
624
+ def instUndetMap ( implicit ctx : Context ) = new TypeMap {
625
625
def apply (t : Type ): Type = t match {
626
626
case tvar : TypeVar if ! tvar.isInstantiated => WildcardType (tvar.origin.underlying.bounds)
627
627
case _ => mapOver(t)
@@ -634,27 +634,27 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
634
634
)
635
635
636
636
val tvars = tp1.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds) }
637
- val protoTp1 = thisTypeMap (tp1.appliedTo(tvars))
637
+ val protoTp1 = childTypeMap.apply (tp1.appliedTo(tvars))
638
638
639
639
// If parent contains a reference to an abstract type, then we should
640
640
// refine subtype checking to eliminate abstract types according to
641
641
// variance. As this logic is only needed in exhaustivity check, thus
642
642
// we manually patch subtyping check instead of changing TypeComparer.
643
643
// See tests/patmat/3645b.scala
644
644
def parentQualify = tp1.widen.classSymbol.info.parents.exists { parent =>
645
- (parent.argInfos.nonEmpty || parent.abstractTypeMembers.nonEmpty) &&
646
- instantiate (parent, tp2)(ctx.fresh.setNewTyperState()).exists
645
+ implicit val ictx = ctx.fresh.setNewTyperState()
646
+ parent.argInfos.nonEmpty && childTypeMap.apply (parent) <:< parentTypeMap.apply(tp2)
647
647
}
648
648
649
649
if (protoTp1 <:< tp2) {
650
650
if (isFullyDefined(protoTp1, force)) protoTp1
651
- else instUndetMap(protoTp1)
651
+ else instUndetMap.apply (protoTp1)
652
652
}
653
653
else {
654
- val protoTp2 = typeParamMap (tp2)
654
+ val protoTp2 = parentTypeMap.apply (tp2)
655
655
if (protoTp1 <:< protoTp2 || parentQualify) {
656
656
if (isFullyDefined(AndType (protoTp1, protoTp2), force)) protoTp1
657
- else instUndetMap(protoTp1)
657
+ else instUndetMap.apply (protoTp1)
658
658
}
659
659
else {
660
660
debug.println(s " $protoTp1 <:< $protoTp2 = false " )
0 commit comments