Skip to content

Commit d5a3b56

Browse files
committed
Use old prioritization for old-style implicits if new is ambiguous
1 parent 3c17abf commit d5a3b56

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,9 @@ trait Implicits:
13311331
else if alt1.level != alt2.level then alt1.level - alt2.level
13321332
else
13331333
var cmp = comp(using searchContext())
1334+
if cmp == 0 && alt1.ref.symbol.is(Implicit) && alt2.ref.symbol.is(Implicit) then
1335+
// if we get an ambiguity with new rules for a pair of old-style implicits, fall back to old rules
1336+
cmp = comp(using searchContext().addMode(Mode.OldImplicitResolution))
13341337
val sv = Feature.sourceVersion
13351338
if isWarnPriorityChangeVersion(sv) then
13361339
val prev = comp(using searchContext().addMode(Mode.OldImplicitResolution))

tests/neg/i2974.scala

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ object Test {
1515
summon[Foo[Int]] // ok
1616

1717
locally:
18-
implicit val fa: Foo[Any] = ???
19-
implicit val ba: Bar[Int] = ???
18+
given fa: Foo[Any] = ???
19+
given ba: Bar[Int] = ???
2020
summon[Foo[Int]] // error: now ambiguous,
2121
// was resolving to `ba` when using intermediate rules:
2222
// better means specialize, but map all type arguments downwards
2323

24+
locally:
25+
implicit val fa: Foo[Any] = ???
26+
implicit val ba: Bar[Int] = ???
27+
summon[Foo[Int]] // is OK since we fall back to old rules for old-style implicits as a tie breaker
2428
}

0 commit comments

Comments
 (0)