Skip to content

Commit c588b1c

Browse files
Remove redundant comparisons in healAmbiguous with disambiguate = true
They are only needed in versions where we may have kept the candidate in pending by either of the two schemes.
1 parent 1e93f22 commit c588b1c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,10 @@ trait Implicits:
13101310
// message if one of the critical candidates is part of the result of the implicit search.
13111311
val priorityChangeWarnings = mutable.ListBuffer[(/*critical:*/ List[TermRef], Message)]()
13121312

1313+
val sv = Feature.sourceVersion
1314+
val isLastOldVersion = sv.stable == SourceVersion.`3.6`
1315+
val isWarnPriorityChangeVersion = isLastOldVersion || sv == SourceVersion.`3.7-migration`
1316+
13131317
/** Compare `alt1` with `alt2` to determine which one should be chosen.
13141318
*
13151319
* @return a number > 0 if `alt1` is preferred over `alt2`
@@ -1333,10 +1337,7 @@ trait Implicits:
13331337
else if alt1.level != alt2.level then alt1.level - alt2.level
13341338
else
13351339
val cmp = comp(using searchContext())
1336-
val sv = Feature.sourceVersion
1337-
val isLastOldVersion = sv.stable == SourceVersion.`3.6`
1338-
val isMigratingVersion = sv == SourceVersion.`3.7-migration`
1339-
if isLastOldVersion || isMigratingVersion then
1340+
if isWarnPriorityChangeVersion then
13401341
val prev = comp(using searchContext().addMode(Mode.OldImplicitResolution))
13411342
if disambiguate && cmp != prev then
13421343
implicits.println(i"PRIORITY CHANGE ${alt1.ref}, ${alt2.ref}")
@@ -1452,7 +1453,8 @@ trait Implicits:
14521453

14531454
val newPending = remaining.filter(betterThanAll(_, disambiguate = false))
14541455
rank(newPending, fail, Nil) match
1455-
case found: SearchSuccess if betterThanAll(found, disambiguate = true) => found
1456+
case found: SearchSuccess
1457+
if !isWarnPriorityChangeVersion || betterThanAll(found, disambiguate = true) => found
14561458
case _ => fail
14571459

14581460
negateIfNot(tryImplicit(cand, contextual)) match {

0 commit comments

Comments
 (0)