@@ -667,44 +667,34 @@ object TypeOps:
667
667
def maxTypeMap (implicit ctx : Context ) = new AbstractTypeMap (maximize = true )
668
668
669
669
// Prefix inference, replace `p.C.this.Child` with `X.Child` where `X <: p.C`
670
- // Note: we need to handle `p` recursively.
670
+ // Note: we need to strip ThisType in `p` recursively.
671
671
//
672
672
// See tests/patmat/i3938.scala
673
673
class InferPrefixMap extends TypeMap {
674
- var tvars = Set .empty[ TypeVar ]
674
+ var prefixTVar : Type = null
675
675
def apply (tp : Type ): Type = tp match {
676
676
case ThisType (tref : TypeRef ) if ! tref.symbol.isStaticOwner =>
677
677
if (tref.symbol.is(Module ))
678
678
TermRef (this (tref.prefix), tref.symbol.sourceModule)
679
+ else if (prefixTVar != null )
680
+ this (tref)
679
681
else {
680
- val bound = TypeRef (this (tref.prefix), tref.symbol)
681
- val tvar = newTypeVar(TypeBounds .upper(bound))
682
- tvars = tvars + tvar
683
- tvar
682
+ prefixTVar = WildcardType // prevent recursive call from assigning it
683
+ prefixTVar = newTypeVar(TypeBounds .upper(this (tref)))
684
+ prefixTVar
684
685
}
685
686
case tp => mapOver(tp)
686
687
}
687
688
}
688
689
689
- // replace uninstantiated type vars with WildcardType, check tests/patmat/3333.scala
690
- def instUndetMap (implicit ctx : Context ) = new TypeMap {
691
- def apply (t : Type ): Type = t match {
692
- case tvar : TypeVar if ! tvar.isInstantiated =>
693
- WildcardType (tvar.origin.underlying.bounds)
694
- case tref : TypeRef if tref.typeSymbol.isPatternBound =>
695
- WildcardType (tref.underlying.bounds)
696
- case _ => mapOver(t)
697
- }
698
- }
699
-
700
690
val inferThisMap = new InferPrefixMap
701
691
val tvars = tp1.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds) }
702
692
val protoTp1 = inferThisMap.apply(tp1).appliedTo(tvars)
703
693
704
694
val force = new ForceDegree .Value (
705
695
tvar =>
706
696
! (ctx.typerState.constraint.entry(tvar.origin) `eq` tvar.origin.underlying) ||
707
- inferThisMap.tvars.contains (tvar), // always instantiate prefix
697
+ (tvar `eq` inferThisMap.prefixTVar ), // always instantiate prefix
708
698
IfBottom .flip
709
699
)
710
700
@@ -721,13 +711,13 @@ object TypeOps:
721
711
722
712
if (protoTp1 <:< tp2) {
723
713
maximizeType(protoTp1, NoSpan , fromScala2x = false )
724
- instUndetMap.apply (protoTp1)
714
+ wildApprox (protoTp1)
725
715
}
726
716
else {
727
717
val protoTp2 = maxTypeMap.apply(tp2)
728
718
if (protoTp1 <:< protoTp2 || parentQualify)
729
719
if (isFullyDefined(AndType (protoTp1, protoTp2), force)) protoTp1
730
- else instUndetMap.apply (protoTp1)
720
+ else wildApprox (protoTp1)
731
721
else {
732
722
typr.println(s " $protoTp1 <:< $protoTp2 = false " )
733
723
NoType
0 commit comments