@@ -1301,9 +1301,10 @@ trait Implicits:
1301
1301
private def searchImplicit (eligible : List [Candidate ], contextual : Boolean ): SearchResult =
1302
1302
1303
1303
// 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 )]()
1307
1308
1308
1309
/** Compare `alt1` with `alt2` to determine which one should be chosen.
1309
1310
*
@@ -1322,7 +1323,7 @@ trait Implicits:
1322
1323
def compareAlternatives (alt1 : RefAndLevel , alt2 : RefAndLevel ): Int =
1323
1324
def comp (using Context ) = explore(compare(alt1.ref, alt2.ref, preferGeneral = true ))
1324
1325
def warn (msg : Message ) =
1325
- priorityChangeWarnings += (alt1.ref -> msg) += ( alt2.ref -> msg)
1326
+ priorityChangeWarnings += (( alt1.ref, alt2.ref, msg) )
1326
1327
if alt1.ref eq alt2.ref then 0
1327
1328
else if alt1.level != alt2.level then alt1.level - alt2.level
1328
1329
else
@@ -1440,7 +1441,11 @@ trait Implicits:
1440
1441
// need a candidate better than `cand`
1441
1442
healAmbiguous(fail, newCand =>
1442
1443
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)
1444
1449
case best : SearchSuccess =>
1445
1450
if (ctx.mode.is(Mode .ImplicitExploration ) || isCoherent)
1446
1451
best
@@ -1596,8 +1601,9 @@ trait Implicits:
1596
1601
throw ex
1597
1602
1598
1603
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)
1601
1607
result
1602
1608
end searchImplicit
1603
1609
0 commit comments