Skip to content

Commit b9764fd

Browse files
committed
Refine criterion for deepening after ambiguities
1 parent e651c0f commit b9764fd

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,7 +3019,9 @@ class Typer extends Namer
30193019
arg.tpe match {
30203020
case failed: AmbiguousImplicits =>
30213021
val pt1 = pt.deepenProto
3022-
if ((pt1 `ne` pt) && constrainResult(tree.symbol, wtp, pt1)) implicitArgs(formals, argIndex, pt1)
3022+
if (pt1 `ne` pt) && (pt1 ne sharpenedPt)
3023+
&& constrainResult(tree.symbol, wtp, pt1)
3024+
then implicitArgs(formals, argIndex, pt1)
30233025
else arg :: implicitArgs(formals1, argIndex + 1, pt1)
30243026
case failed: SearchFailureType if !hasDefaultParams =>
30253027
// no need to search further, the adapt fails in any case
@@ -3264,6 +3266,16 @@ class Typer extends Namer
32643266
case _ => tp
32653267
}
32663268

3269+
// If the expected type is a selection of an extension method, deepen it
3270+
// to also propagate the argument type (which is the receiver we have
3271+
// typechecked already). This is needed for i8311.scala. Doing so
3272+
// for all expected types does not work since it would block the case
3273+
// where we have an argument that must be converted with another
3274+
// implicit conversion to the receiver type.
3275+
def sharpenedPt = pt match
3276+
case pt: SelectionProto if pt.name.isExtensionName => pt.deepenProto
3277+
case _ => pt
3278+
32673279
def adaptNoArgs(wtp: Type): Tree = {
32683280
val ptNorm = underlyingApplied(pt)
32693281
def functionExpected = defn.isFunctionType(ptNorm)
@@ -3272,15 +3284,6 @@ class Typer extends Namer
32723284
case IgnoredProto(_: FunOrPolyProto) => false
32733285
case _ => true
32743286
}
3275-
// If the expected type is a selection of an extension method, deepen it
3276-
// to also propagate the argument type (which is the receiver we have
3277-
// typechecked already). This is needed for i8311.scala. Doing so
3278-
// for all expected types does not work since it would block the case
3279-
// where we have an argument that must be converted with another
3280-
// implicit conversion to the receiver type.
3281-
def sharpenedPt = pt match
3282-
case pt: SelectionProto if pt.name.isExtensionName => pt.deepenProto
3283-
case _ => pt
32843287
var resMatch: Boolean = false
32853288
wtp match {
32863289
case wtp: ExprType =>

0 commit comments

Comments
 (0)