Skip to content

Commit

Permalink
Avoid ambiguity errors arising from double references in implicits
Browse files Browse the repository at this point in the history
If two implicit candidate references happen to be the same pick one of them instead
of reporting an ambiguity.
  • Loading branch information
odersky committed May 6, 2024
1 parent 33f801b commit 8a3854f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,9 @@ trait Implicits:
case alt1: SearchSuccess =>
var diff = compareAlternatives(alt1, alt2)
assert(diff <= 0) // diff > 0 candidates should already have been eliminated in `rank`
if diff == 0 && alt2.isExtension then
if diff == 0 && alt1.ref =:= alt2.ref then
diff = 1 // See i12951 for a test where this happens
else if diff == 0 && alt2.isExtension then
if alt1.isExtension then
// Fall back: if both results are extension method applications,
// compare the extension methods instead of their wrappers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ object Foo:

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

File renamed without changes.

0 comments on commit 8a3854f

Please sign in to comment.