Skip to content

Commit

Permalink
Merge pull request #10706 from som-snytt/issue/12967-msg
Browse files Browse the repository at this point in the history
Improve symbol in implicit result check [ci: last-only]
  • Loading branch information
lrytz committed Mar 13, 2024
2 parents 1bdf362 + 3015a04 commit 266f8f0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/compiler/scala/tools/nsc/typechecker/Implicits.scala
Expand Up @@ -126,14 +126,19 @@ trait Implicits extends splain.SplainData {
if (settings.areStatisticsEnabled) statistics.stopCounter(findMemberImpl, findMemberStart)
if (settings.areStatisticsEnabled) statistics.stopCounter(subtypeImpl, subtypeStart)

val rts = result.tree.symbol
if (result.isSuccess && rts != null) {
if (result.isSuccess) {
val rts = {
val infoSym = if (result.implicitInfo != null) result.implicitInfo.sym else NoSymbol
infoSym.orElse {
val rts0 = result.tree.symbol
if (rts0 != null) rts0 else NoSymbol
}
}
if (settings.lintImplicitRecursion) {
val s = if (rts.isAccessor) rts.accessed else if (rts.isModule) rts.moduleClass else rts
if (s != NoSymbol && context.owner.hasTransOwner(s))
context.warning(result.tree.pos, s"Implicit resolves to enclosing $rts", WarningCategory.WFlagSelfImplicit)
}

if (result.inPackagePrefix && currentRun.isScala3) {
val msg =
s"""Implicit $rts was found in a package prefix of the required type, which is not part of the implicit scope in Scala 3.
Expand Down
8 changes: 7 additions & 1 deletion test/files/neg/t12919.check
Expand Up @@ -4,4 +4,10 @@ Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=b.V.f
def f(xs: List[a.A]) = xs.sorted // warn
^
1 error
t12919.scala:48: error: Implicit method myClassToSeq was found in a package prefix of the required type, which is not part of the implicit scope in Scala 3.
For migration, add `import a1.a2.myClassToSeq`.
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=a1.Main.f
def f[A](x: Seq[a1.a2.MyClass[A]]): Seq[A] = x.flatten
^
2 errors
16 changes: 15 additions & 1 deletion test/files/neg/t12919.scala
@@ -1,4 +1,4 @@
// scalac: -Xsource:3 -Werror
//> using options -Xsource:3 -Werror

package object a {
implicit val aOrd: Ordering[A] = null
Expand Down Expand Up @@ -34,3 +34,17 @@ package c {
}
}

package a1 {

package object a2 {
implicit def myClassToSeq[A](a: MyClass[A]): Seq[A] = a.values
}

package a2 {
case class MyClass[A](values: Seq[A])
}

object Main {
def f[A](x: Seq[a1.a2.MyClass[A]]): Seq[A] = x.flatten
}
}

0 comments on commit 266f8f0

Please sign in to comment.