diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index bb35306f696c..0afcbc4e0bc9 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -1582,6 +1582,7 @@ trait Implicits: else candSucceedsGiven(sym.owner) ctx.isTyper + && pt.isValueType && !candSym.isOneOf(TermParamOrAccessor | Synthetic) && candSym.span.exists && candSucceedsGiven(ctx.owner) @@ -1592,12 +1593,13 @@ trait Implicits: def checkResolutionChange(result: SearchResult) = result match case result: SearchSuccess if (eligible ne preEligible) && !sourceVersion.isAtLeast(SourceVersion.`future`) => + val newSym = result.ref.symbol searchImplicit(preEligible.diff(eligible), contextual) match - case prevResult: SearchSuccess => + case prevResult: SearchSuccess if prevResult.ref.symbol != newSym => report.error( em"""Warning: result of implicit search for $pt will change. - |current result: ${prevResult.ref.symbol.showLocated} - |result with -source future: ${result.ref.symbol.showLocated}""", + |Current result: ${prevResult.ref.symbol.showLocated} + |Result with -source future: ${newSym.showLocated}""", srcPos ) case _ => diff --git a/tests/neg/i15474.check b/tests/neg/i15474.check index 267a02a80786..edbe5874a458 100644 --- a/tests/neg/i15474.check +++ b/tests/neg/i15474.check @@ -1,6 +1,6 @@ --- Error: tests/neg/i15474.scala:16:56 --------------------------------------------------------------------------------- -16 | given Ordering[Price] = summon[Ordering[BigDecimal]] // error - | ^ - | Warning: result of implicit search for Ordering[BigDecimal] will change. - | current result: given instance given_Ordering_Price in object Price - | result with -source future: object BigDecimal in object Ordering +-- Error: tests/neg/i15474.scala:7:56 ---------------------------------------------------------------------------------- +7 | given Ordering[Price] = summon[Ordering[BigDecimal]] // error + | ^ + | Warning: result of implicit search for Ordering[BigDecimal] will change. + | Current result: given instance given_Ordering_Price in object Price + | Result with -source future: object BigDecimal in object Ordering diff --git a/tests/neg/i15474.scala b/tests/neg/i15474.scala index c5cf934bdd7a..de4943741021 100644 --- a/tests/neg/i15474.scala +++ b/tests/neg/i15474.scala @@ -1,14 +1,5 @@ //> using options -Xfatal-warnings -import scala.language.implicitConversions - -object Test1: - given c: Conversion[ String, Int ] with - def apply(from: String): Int = from.toInt // was error, now avoided - -object Test2: - given c: Conversion[ String, Int ] = _.toInt // now avoided, was loop not detected, could be used as a fallback to avoid the warning. - object Prices { opaque type Price = BigDecimal diff --git a/tests/neg/i15474b.check b/tests/neg/i15474b.check new file mode 100644 index 000000000000..d3730026d452 --- /dev/null +++ b/tests/neg/i15474b.check @@ -0,0 +1,5 @@ +-- Error: tests/neg/i15474b.scala:7:40 --------------------------------------------------------------------------------- +7 | def apply(from: String): Int = from.toInt // error + | ^^^^^^^^^^ + | Infinite loop in function body + | Test1.c.apply(from).toInt diff --git a/tests/neg/i15474b.scala b/tests/neg/i15474b.scala new file mode 100644 index 000000000000..cdda5147a279 --- /dev/null +++ b/tests/neg/i15474b.scala @@ -0,0 +1,11 @@ +//> using options -Xfatal-warnings + +import scala.language.implicitConversions + +object Test1: + given c: Conversion[ String, Int ] with + def apply(from: String): Int = from.toInt // error + +object Test2: + given c: Conversion[ String, Int ] = _.toInt // loop not detected, could be used as a fallback to avoid the warning. + diff --git a/tests/neg/i6716.check b/tests/neg/i6716.check index 1e1359442bec..8f1d829519dc 100644 --- a/tests/neg/i6716.check +++ b/tests/neg/i6716.check @@ -2,5 +2,5 @@ 12 | given Monad[Bar] = summon[Monad[Foo]] // error | ^ | Warning: result of implicit search for Monad[Foo] will change. - | current result: given instance given_Monad_Bar in object Bar - | result with -source future: object given_Monad_Foo in object Foo + | Current result: given instance given_Monad_Bar in object Bar + | Result with -source future: object given_Monad_Foo in object Foo diff --git a/tests/pos/i15474.scala b/tests/pos/i15474.scala index e40e11d84581..5167f6c4c954 100644 --- a/tests/pos/i15474.scala +++ b/tests/pos/i15474.scala @@ -1,14 +1,8 @@ //> using options -Xfatal-warnings + import scala.language.implicitConversions import language.future -object Test1: - given c: Conversion[ String, Int ] with - def apply(from: String): Int = from.toInt // was error, now avoided - -object Test2: - given c: Conversion[ String, Int ] = _.toInt // now avoided, was loop not detected, could be used as a fallback to avoid the warning. - object Prices { opaque type Price = BigDecimal