Skip to content

Commit 8a3854f

Browse files
committed
Avoid ambiguity errors arising from double references in implicits
If two implicit candidate references happen to be the same pick one of them instead of reporting an ambiguity.
1 parent 33f801b commit 8a3854f

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,9 @@ trait Implicits:
13401340
case alt1: SearchSuccess =>
13411341
var diff = compareAlternatives(alt1, alt2)
13421342
assert(diff <= 0) // diff > 0 candidates should already have been eliminated in `rank`
1343-
if diff == 0 && alt2.isExtension then
1343+
if diff == 0 && alt1.ref =:= alt2.ref then
1344+
diff = 1 // See i12951 for a test where this happens
1345+
else if diff == 0 && alt2.isExtension then
13441346
if alt1.isExtension then
13451347
// Fall back: if both results are extension method applications,
13461348
// compare the extension methods instead of their wrappers.

tests/neg/i12591/Inner.scala renamed to tests/pos/i12591/Inner.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ object Foo:
99

1010
import Foo.TC
1111
//Adding import Foo.Bar resolves the issue
12-
val badSummon = summon[TC[Bar]] // error here
12+
val badSummon = summon[TC[Bar]]
13+
// was an ambiguous error, now OK, since the two references are the same
1314

File renamed without changes.

0 commit comments

Comments
 (0)