@@ -38,13 +38,13 @@ object ProtoTypes {
38
38
def isCompatible (tp : Type , pt : Type )(using Context ): Boolean =
39
39
(tp.widenExpr relaxed_<:< pt.widenExpr) || viewExists(tp, pt)
40
40
41
- /** Like isCompatibe, but using a subtype comparison with necessary eithers
42
- * that don't unnecessarily truncate the constraint space, returning false instead.
41
+ /** Like normalize and then isCompatible, but using a subtype comparison with
42
+ * necessary eithers that does not unnecessarily truncate the constraint space,
43
+ * returning false instead.
43
44
*/
44
45
def necessarilyCompatible (tp : Type , pt : Type )(using Context ): Boolean =
45
- val tpw = tp.widenExpr
46
- val ptw = pt.widenExpr
47
- necessarySubType(tpw, ptw) || tpw.isValueSubType(ptw) || viewExists(tp, pt)
46
+ val tpn = normalize(tp, pt, followIFT = ! defn.isContextFunctionType(pt))
47
+ necessarySubType(tpn, pt) || tpn.isValueSubType(pt) || viewExists(tpn, pt)
48
48
49
49
/** Test compatibility after normalization.
50
50
* Do this in a fresh typerstate unless `keepConstraint` is true.
@@ -84,9 +84,9 @@ object ProtoTypes {
84
84
case _ => true
85
85
}
86
86
case _ : ValueTypeOrProto if ! disregardProto(pt) =>
87
- necessarilyCompatible(normalize(mt, pt) , pt)
87
+ necessarilyCompatible(mt , pt)
88
88
case pt : WildcardType if pt.optBounds.exists =>
89
- necessarilyCompatible(normalize(mt, pt) , pt)
89
+ necessarilyCompatible(mt , pt)
90
90
case _ =>
91
91
true
92
92
}
@@ -601,7 +601,7 @@ object ProtoTypes {
601
601
* of toString method. The problem is solved by dereferencing nullary method types if the corresponding
602
602
* function type is not compatible with the prototype.
603
603
*/
604
- def normalize (tp : Type , pt : Type )(using Context ): Type = {
604
+ def normalize (tp : Type , pt : Type , followIFT : Boolean = true )(using Context ): Type = {
605
605
Stats .record(" normalize" )
606
606
tp.widenSingleton match {
607
607
case poly : PolyType =>
@@ -626,7 +626,7 @@ object ProtoTypes {
626
626
normalize(et.resultType, pt)
627
627
case wtp =>
628
628
val iftp = defn.asContextFunctionType(wtp)
629
- if iftp.exists then normalize(iftp.dropDependentRefinement.argInfos.last, pt)
629
+ if iftp.exists && followIFT then normalize(iftp.dropDependentRefinement.argInfos.last, pt)
630
630
else tp
631
631
}
632
632
}
0 commit comments