@@ -1301,9 +1301,10 @@ trait Implicits:
13011301 private def searchImplicit (eligible : List [Candidate ], contextual : Boolean ): SearchResult =
13021302
13031303 // A map that associates a priority change warning (between -source 3.4 and 3.6)
1304- // with a candidate ref mentioned in the warning. We report the associated
1305- // message if the candidate ref is part of the result of the implicit search
1306- var priorityChangeWarnings = mutable.ListBuffer [(TermRef , Message )]()
1304+ // with the candidate refs mentioned in the warning. We report the associated
1305+ // message if both candidates qualify in tryImplicit and at least one of the candidates
1306+ // is part of the result of the implicit search.
1307+ val priorityChangeWarnings = mutable.ListBuffer [(TermRef , TermRef , Message )]()
13071308
13081309 /** Compare `alt1` with `alt2` to determine which one should be chosen.
13091310 *
@@ -1322,7 +1323,7 @@ trait Implicits:
13221323 def compareAlternatives (alt1 : RefAndLevel , alt2 : RefAndLevel ): Int =
13231324 def comp (using Context ) = explore(compare(alt1.ref, alt2.ref, preferGeneral = true ))
13241325 def warn (msg : Message ) =
1325- priorityChangeWarnings += (alt1.ref -> msg) += ( alt2.ref -> msg)
1326+ priorityChangeWarnings += (( alt1.ref, alt2.ref, msg) )
13261327 if alt1.ref eq alt2.ref then 0
13271328 else if alt1.level != alt2.level then alt1.level - alt2.level
13281329 else
@@ -1440,7 +1441,11 @@ trait Implicits:
14401441 // need a candidate better than `cand`
14411442 healAmbiguous(fail, newCand =>
14421443 compareAlternatives(newCand, cand) > 0 )
1443- else rank(remaining, found, fail :: rfailures)
1444+ else
1445+ // keep only warnings that don't involve the failed candidate reference
1446+ priorityChangeWarnings.filterInPlace: (ref1, ref2, _) =>
1447+ ref1 != cand.ref && ref2 != cand.ref
1448+ rank(remaining, found, fail :: rfailures)
14441449 case best : SearchSuccess =>
14451450 if (ctx.mode.is(Mode .ImplicitExploration ) || isCoherent)
14461451 best
@@ -1596,8 +1601,9 @@ trait Implicits:
15961601 throw ex
15971602
15981603 val result = rank(sort(eligible), NoMatchingImplicitsFailure , Nil )
1599- for (ref, msg) <- priorityChangeWarnings do
1600- if result.found.contains(ref) then report.warning(msg, srcPos)
1604+ for (ref1, ref2, msg) <- priorityChangeWarnings do
1605+ if result.found.exists(ref => ref == ref1 || ref == ref2) then
1606+ report.warning(msg, srcPos)
16011607 result
16021608 end searchImplicit
16031609
0 commit comments