Skip to content

Commit

Permalink
Fixup, skip adapting to non-conversions, and all prototypes
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Jun 5, 2023
1 parent 2517f38 commit 701254f
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1125,18 +1125,22 @@ trait Implicits:
def conversionResultType(info: Type): Type = info match
case info: PolyType => conversionResultType(info.resType)
case info: MethodType if info.isImplicitMethod => conversionResultType(info.resType)
case _ if info.derivesFrom(defn.ConversionClass) => pt match
case selProto: SelectionProto =>
info.baseType(defn.ConversionClass) match
case AppliedType(_, List(_, restpe)) if selProto.isMatchedBy(restpe) =>
// if we embed the SelectionProto as the Conversion result type
// it might end up within a GADT cast type
// so instead replace it with the targeted conversion type, if it matches
// see tests/pos/i15867.scala.
restpe
case _ => pt
case _ => pt
case _ => NoType
case _ =>
if info.derivesFrom(defn.ConversionClass) then
pt match
case selProto: SelectionProto =>
// we want to avoid embedding a SelectionProto in a Conversion, as the result type
// as it might end up within a GADT cast type, e.g. tests/pos/i15867.scala
// so, if we can find the target result type - as in,
// if it matches the selection prototype, then let's adapt to that instead
// otherwise just skip adapting with a prototype (by returning NoType)
info.baseType(defn.ConversionClass) match
case AppliedType(_, List(_, restpe)) if selProto.isMatchedBy(restpe) =>
restpe
case _ => NoType // can't find conversion result type, avoid adapting with SelectionProto
case _: ProtoType => NoType // avoid adapting with ProtoType
case _ => pt // not a ProtoType, so use it for adapting
else NoType // not a Conversion, don't adapt
def tryConversion(using Context) = {
val restpeConv = if ref.symbol.is(Given) then conversionResultType(ref.widenTermRefExpr) else NoType
val untpdConv =
Expand Down

0 comments on commit 701254f

Please sign in to comment.