From 701254f9a9104c7206241e498f7e9911558b1c26 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Mon, 5 Jun 2023 15:12:44 +0100 Subject: [PATCH] Fixup, skip adapting to non-conversions, and all prototypes --- .../dotty/tools/dotc/typer/Implicits.scala | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index 29337165272a..0d40f818fd86 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -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 =