Skip to content

Commit 701254f

Browse files
committed
Fixup, skip adapting to non-conversions, and all prototypes
1 parent 2517f38 commit 701254f

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,18 +1125,22 @@ trait Implicits:
11251125
def conversionResultType(info: Type): Type = info match
11261126
case info: PolyType => conversionResultType(info.resType)
11271127
case info: MethodType if info.isImplicitMethod => conversionResultType(info.resType)
1128-
case _ if info.derivesFrom(defn.ConversionClass) => pt match
1129-
case selProto: SelectionProto =>
1130-
info.baseType(defn.ConversionClass) match
1131-
case AppliedType(_, List(_, restpe)) if selProto.isMatchedBy(restpe) =>
1132-
// if we embed the SelectionProto as the Conversion result type
1133-
// it might end up within a GADT cast type
1134-
// so instead replace it with the targeted conversion type, if it matches
1135-
// see tests/pos/i15867.scala.
1136-
restpe
1137-
case _ => pt
1138-
case _ => pt
1139-
case _ => NoType
1128+
case _ =>
1129+
if info.derivesFrom(defn.ConversionClass) then
1130+
pt match
1131+
case selProto: SelectionProto =>
1132+
// we want to avoid embedding a SelectionProto in a Conversion, as the result type
1133+
// as it might end up within a GADT cast type, e.g. tests/pos/i15867.scala
1134+
// so, if we can find the target result type - as in,
1135+
// if it matches the selection prototype, then let's adapt to that instead
1136+
// otherwise just skip adapting with a prototype (by returning NoType)
1137+
info.baseType(defn.ConversionClass) match
1138+
case AppliedType(_, List(_, restpe)) if selProto.isMatchedBy(restpe) =>
1139+
restpe
1140+
case _ => NoType // can't find conversion result type, avoid adapting with SelectionProto
1141+
case _: ProtoType => NoType // avoid adapting with ProtoType
1142+
case _ => pt // not a ProtoType, so use it for adapting
1143+
else NoType // not a Conversion, don't adapt
11401144
def tryConversion(using Context) = {
11411145
val restpeConv = if ref.symbol.is(Given) then conversionResultType(ref.widenTermRefExpr) else NoType
11421146
val untpdConv =

0 commit comments

Comments
 (0)