Skip to content

Commit dda9518

Browse files
committed
Filter out more false positives in priority change warnings
1 parent 27d08b6 commit dda9518

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Diff for: compiler/src/dotty/tools/dotc/typer/Implicits.scala

+12-8
Original file line numberDiff line numberDiff line change
@@ -1318,16 +1318,14 @@ trait Implicits:
13181318
* return new result with preferGeneral = true
13191319
* 3.6 and higher: compare with preferGeneral = true
13201320
*
1321+
* @param disambiguate The call is used to disambiguate two successes, not for ranking.
1322+
* When ranking, we are always filtering out either > 0 or <= 0 results.
1323+
* In each case a priority change from 0 to -1 or vice versa makes no difference.
13211324
* @param only2ndCritical If true only the second alternative is critical in case
13221325
* of a priority change.
13231326
*/
1324-
def compareAlternatives(alt1: RefAndLevel, alt2: RefAndLevel, only2ndCritical: Boolean = false): Int =
1327+
def compareAlternatives(alt1: RefAndLevel, alt2: RefAndLevel, disambiguate: Boolean = false, only2ndCritical: Boolean = false): Int =
13251328
def comp(using Context) = explore(compare(alt1.ref, alt2.ref, preferGeneral = true))
1326-
def warn(msg: Message) =
1327-
val critical =
1328-
if only2ndCritical then alt2.ref :: Nil
1329-
else alt1.ref :: alt2.ref :: Nil
1330-
priorityChangeWarnings += ((critical, msg))
13311329
if alt1.ref eq alt2.ref then 0
13321330
else if alt1.level != alt2.level then alt1.level - alt2.level
13331331
else
@@ -1336,6 +1334,12 @@ trait Implicits:
13361334
if sv.stable == SourceVersion.`3.5` || sv == SourceVersion.`3.6-migration` then
13371335
val prev = comp(using searchContext().addMode(Mode.OldImplicitResolution))
13381336
if cmp != prev then
1337+
def warn(msg: Message) =
1338+
if disambiguate || cmp > 0 || prev > 0 then
1339+
val critical =
1340+
if only2ndCritical then alt2.ref :: Nil
1341+
else alt1.ref :: alt2.ref :: Nil
1342+
priorityChangeWarnings += ((critical, msg))
13391343
def choice(c: Int) = c match
13401344
case -1 => "the second alternative"
13411345
case 1 => "the first alternative"
@@ -1362,7 +1366,7 @@ trait Implicits:
13621366
*/
13631367
def disambiguate(alt1: SearchResult, alt2: SearchSuccess) = alt1 match
13641368
case alt1: SearchSuccess =>
1365-
var diff = compareAlternatives(alt1, alt2)
1369+
var diff = compareAlternatives(alt1, alt2, disambiguate = true)
13661370
assert(diff <= 0) // diff > 0 candidates should already have been eliminated in `rank`
13671371
if diff == 0 && alt1.ref =:= alt2.ref then
13681372
diff = 1 // See i12951 for a test where this happens
@@ -1463,7 +1467,7 @@ trait Implicits:
14631467
// `retained`. Therefore, it's a priorty change only if the
14641468
// second alternative appears in the final search result. Otherwise
14651469
// we have the following scenario:
1466-
// - 1st alternative, bit not snd appears in final result
1470+
// - 1st alternative, but not snd appears in final result
14671471
// - Hence, snd was eliminated either here, or otherwise by a direct
14681472
// comparison later.
14691473
// - Hence, no change in resolution.

0 commit comments

Comments
 (0)