@@ -1455,16 +1455,29 @@ trait Implicits { self: Typer =>
1455
1455
* - If alt2 is preferred over alt1, pick alt2, otherwise return an
1456
1456
* ambiguous implicits error.
1457
1457
*/
1458
- def disambiguate (alt1 : SearchResult , alt2 : SearchSuccess ) = alt1 match {
1458
+ def disambiguate (alt1 : SearchResult , alt2 : SearchSuccess ) = alt1 match
1459
1459
case alt1 : SearchSuccess =>
1460
- val diff = compareCandidate(alt1, alt2.ref, alt2.level)
1460
+ var diff = compareCandidate(alt1, alt2.ref, alt2.level)
1461
1461
assert(diff <= 0 ) // diff > 0 candidates should already have been eliminated in `rank`
1462
- if (diff < 0 ) alt2
1463
- else
1464
- // numericValueTypeBreak(alt1, alt2) recoverWith
1465
- SearchFailure (new AmbiguousImplicits (alt1, alt2, pt, argument))
1462
+
1463
+ if diff == 0 then
1464
+ // Fall back: if both results are extension method applications,
1465
+ // compare the extension methods instead of their wrappers.
1466
+ object extMethodApply with
1467
+ def unapply (t : Tree ): Option [Type ] = t match
1468
+ case t : Applications .ExtMethodApply => Some (methPart(stripApply(t.app)).tpe)
1469
+ case _ => None
1470
+ end extMethodApply
1471
+
1472
+ (alt1.tree, alt2.tree) match
1473
+ case (extMethodApply(ref1 : TermRef ), extMethodApply(ref2 : TermRef )) =>
1474
+ diff = compare(ref1, ref2)
1475
+ case _ =>
1476
+
1477
+ if diff < 0 then alt2
1478
+ else if diff > 0 then alt1
1479
+ else SearchFailure (new AmbiguousImplicits (alt1, alt2, pt, argument))
1466
1480
case _ : SearchFailure => alt2
1467
- }
1468
1481
1469
1482
/** Faced with an ambiguous implicits failure `fail`, try to find another
1470
1483
* alternative among `pending` that is strictly better than both ambiguous
0 commit comments