@@ -1587,46 +1587,54 @@ trait Implicits:
1587
1587
&& candSucceedsGiven(ctx.owner)
1588
1588
end comesTooLate
1589
1589
1590
- val eligible = if contextual then preEligible.filterNot(comesTooLate) else preEligible
1590
+ val eligible = // the eligible candidates that come before the search point
1591
+ if contextual && sourceVersion.isAtLeast(SourceVersion .`3.4`)
1592
+ then preEligible.filterNot(comesTooLate)
1593
+ else preEligible
1591
1594
1592
1595
def checkResolutionChange (result : SearchResult ) =
1593
1596
if (eligible ne preEligible)
1594
1597
&& ! Feature .enabled(Feature .avoidLoopingGivens)
1595
- then searchImplicit(preEligible.diff(eligible), contextual) match
1596
- case prevResult : SearchSuccess =>
1597
- def remedy = pt match
1598
- case _ : SelectionProto =>
1599
- " conversion,\n - use an import to get extension method into scope"
1600
- case _ : ViewProto =>
1601
- " conversion"
1602
- case _ =>
1603
- " argument"
1604
-
1605
- def showResult (r : SearchResult ) = r match
1606
- case r : SearchSuccess => ctx.printer.toTextRef(r.ref).show
1607
- case r => r.show
1608
-
1609
- result match
1610
- case result : SearchSuccess if prevResult.ref frozen_=:= result.ref =>
1611
- // OK
1612
- case _ =>
1613
- report.error(
1614
- em """ Warning: result of implicit search for $pt will change.
1615
- |Current result ${showResult(prevResult)} will be no longer eligible
1616
- | because it is not defined before the search position.
1617
- |Result with new rules: ${showResult(result)}.
1618
- |To opt into the new rules, use the `avoidLoopingGivens` language import,
1619
- |
1620
- |To fix the problem you could try one of the following:
1621
- | - rearrange definitions,
1622
- | - use an explicit $remedy. """ ,
1623
- srcPos)
1624
- case _ =>
1598
+ then
1599
+ val prevResult = searchImplicit(preEligible, contextual)
1600
+ prevResult match
1601
+ case prevResult : SearchSuccess =>
1602
+ def remedy = pt match
1603
+ case _ : SelectionProto =>
1604
+ " conversion,\n - use an import to get extension method into scope"
1605
+ case _ : ViewProto =>
1606
+ " conversion"
1607
+ case _ =>
1608
+ " argument"
1609
+
1610
+ def showResult (r : SearchResult ) = r match
1611
+ case r : SearchSuccess => ctx.printer.toTextRef(r.ref).show
1612
+ case r => r.show
1613
+
1614
+ result match
1615
+ case result : SearchSuccess if prevResult.ref frozen_=:= result.ref =>
1616
+ // OK
1617
+ case _ =>
1618
+ report.error(
1619
+ em """ Warning: result of implicit search for $pt will change.
1620
+ |Current result ${showResult(prevResult)} will be no longer eligible
1621
+ | because it is not defined before the search position.
1622
+ |Result with new rules: ${showResult(result)}.
1623
+ |To opt into the new rules, use the `experimental.avoidLoopingGivens` language import.
1624
+ |
1625
+ |To fix the problem without the language import, you could try one of the following:
1626
+ | - rearrange definitions so that ${showResult(prevResult)} comes earlier,
1627
+ | - use an explicit $remedy. """ ,
1628
+ srcPos)
1629
+ case _ =>
1630
+ prevResult
1631
+ else result
1625
1632
end checkResolutionChange
1626
1633
1627
- searchImplicit(eligible, contextual) match
1634
+ val result = searchImplicit(eligible, contextual)
1635
+ result match
1628
1636
case result : SearchSuccess =>
1629
- result
1637
+ checkResolutionChange( result)
1630
1638
case failure : SearchFailure =>
1631
1639
failure.reason match
1632
1640
case _ : AmbiguousImplicits => failure
@@ -1641,15 +1649,14 @@ trait Implicits:
1641
1649
else ctxImplicits.nn.outerImplicits: ContextualImplicits | Null
1642
1650
// !!! Dotty problem: without the ContextualImplicits | Null type ascription
1643
1651
// we get a Ycheck failure after arrayConstructors due to "Types differ"
1644
- val result = searchImplicit(newCtxImplicits).recoverWith:
1645
- failure2 => failure2.reason match
1646
- case _ : AmbiguousImplicits => failure2
1647
- case _ =>
1648
- reason match
1649
- case (_ : DivergingImplicit ) => failure
1650
- case _ => List (failure, failure2).maxBy(_.tree.treeSize)
1651
- checkResolutionChange(result)
1652
- result
1652
+ checkResolutionChange :
1653
+ searchImplicit(newCtxImplicits).recoverWith:
1654
+ failure2 => failure2.reason match
1655
+ case _ : AmbiguousImplicits => failure2
1656
+ case _ =>
1657
+ reason match
1658
+ case (_ : DivergingImplicit ) => failure
1659
+ case _ => List (failure, failure2).maxBy(_.tree.treeSize)
1653
1660
else failure
1654
1661
end searchImplicit
1655
1662
0 commit comments