@@ -1318,16 +1318,14 @@ trait Implicits:
1318
1318
* return new result with preferGeneral = true
1319
1319
* 3.6 and higher: compare with preferGeneral = true
1320
1320
*
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.
1321
1324
* @param only2ndCritical If true only the second alternative is critical in case
1322
1325
* of a priority change.
1323
1326
*/
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 =
1325
1328
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))
1331
1329
if alt1.ref eq alt2.ref then 0
1332
1330
else if alt1.level != alt2.level then alt1.level - alt2.level
1333
1331
else
@@ -1336,6 +1334,12 @@ trait Implicits:
1336
1334
if sv.stable == SourceVersion .`3.5` || sv == SourceVersion .`3.6-migration` then
1337
1335
val prev = comp(using searchContext().addMode(Mode .OldImplicitResolution ))
1338
1336
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))
1339
1343
def choice (c : Int ) = c match
1340
1344
case - 1 => " the second alternative"
1341
1345
case 1 => " the first alternative"
@@ -1362,7 +1366,7 @@ trait Implicits:
1362
1366
*/
1363
1367
def disambiguate (alt1 : SearchResult , alt2 : SearchSuccess ) = alt1 match
1364
1368
case alt1 : SearchSuccess =>
1365
- var diff = compareAlternatives(alt1, alt2)
1369
+ var diff = compareAlternatives(alt1, alt2, disambiguate = true )
1366
1370
assert(diff <= 0 ) // diff > 0 candidates should already have been eliminated in `rank`
1367
1371
if diff == 0 && alt1.ref =:= alt2.ref then
1368
1372
diff = 1 // See i12951 for a test where this happens
@@ -1463,7 +1467,7 @@ trait Implicits:
1463
1467
// `retained`. Therefore, it's a priorty change only if the
1464
1468
// second alternative appears in the final search result. Otherwise
1465
1469
// 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
1467
1471
// - Hence, snd was eliminated either here, or otherwise by a direct
1468
1472
// comparison later.
1469
1473
// - Hence, no change in resolution.
0 commit comments