Skip to content

Commit 01ec288

Browse files
committed
Refine criterion for deepening after ambiguities
1 parent 026b58a commit 01ec288

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
@@ -2998,7 +2998,9 @@ class Typer extends Namer
29982998
arg.tpe match {
29992999
case failed: AmbiguousImplicits =>
30003000
val pt1 = pt.deepenProto
3001-
if ((pt1 `ne` pt) && constrainResult(tree.symbol, wtp, pt1)) implicitArgs(formals, argIndex, pt1)
3001+
if (pt1 `ne` pt) && (pt1 ne sharpenedPt)
3002+
&& constrainResult(tree.symbol, wtp, pt1)
3003+
then implicitArgs(formals, argIndex, pt1)
30023004
else arg :: implicitArgs(formals1, argIndex + 1, pt1)
30033005
case failed: SearchFailureType if !hasDefaultParams =>
30043006
// no need to search further, the adapt fails in any case
@@ -3243,6 +3245,16 @@ class Typer extends Namer
32433245
case _ => tp
32443246
}
32453247

3248+
// If the expected type is a selection of an extension method, deepen it
3249+
// to also propagate the argument type (which is the receiver we have
3250+
// typechecked already). This is needed for i8311.scala. Doing so
3251+
// for all expected types does not work since it would block the case
3252+
// where we have an argument that must be converted with another
3253+
// implicit conversion to the receiver type.
3254+
def sharpenedPt = pt match
3255+
case pt: SelectionProto if pt.name.isExtensionName => pt.deepenProto
3256+
case _ => pt
3257+
32463258
def adaptNoArgs(wtp: Type): Tree = {
32473259
val ptNorm = underlyingApplied(pt)
32483260
def functionExpected = defn.isFunctionType(ptNorm)
@@ -3251,15 +3263,6 @@ class Typer extends Namer
32513263
case IgnoredProto(_: FunOrPolyProto) => false
32523264
case _ => true
32533265
}
3254-
// If the expected type is a selection of an extension method, deepen it
3255-
// to also propagate the argument type (which is the receiver we have
3256-
// typechecked already). This is needed for i8311.scala. Doing so
3257-
// for all expected types does not work since it would block the case
3258-
// where we have an argument that must be converted with another
3259-
// implicit conversion to the receiver type.
3260-
def sharpenedPt = pt match
3261-
case pt: SelectionProto if pt.name.isExtensionName => pt.deepenProto
3262-
case _ => pt
32633266
var resMatch: Boolean = false
32643267
wtp match {
32653268
case wtp: ExprType =>

0 commit comments

Comments
 (0)