Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spurious deprecation warning with partial function #13000

Open
lrytz opened this issue May 22, 2024 · 0 comments
Open

Spurious deprecation warning with partial function #13000

lrytz opened this issue May 22, 2024 · 0 comments
Milestone

Comments

@lrytz
Copy link
Member

lrytz commented May 22, 2024

Scala 2.13.14

@deprecated abstract class K {
  def prop: Boolean
}

class Test {
  @annotation.nowarn("cat=deprecation")
  def l: List[K] = Nil

  def t = l collect {
    case k if k.prop => k.toString
  }
}
➜ sandbox sc T.scala -deprecation
> scala compile --server=false -S 2.13 -d . -release 8 T.scala -deprecation
/Users/luc/code/scala/scala13/sandbox/T.scala:9: warning: class K is deprecated
  def t = l collect {
                    ^
1 warning

The AST is

Test.this.l.collect[String](({
  @SerialVersionUID(value = 0) final <synthetic> class $anonfun extends scala.runtime.AbstractPartialFunction[K,String] with java.io.Serializable {
    final override def applyOrElse[A1 <: K, B1 >: String](x1: A1, default: A1 => B1): B1 = ((x1.asInstanceOf[K]: K): K @unchecked) match {
      case (k @ _) if k.prop => k.toString()
      case (defaultCase$ @ _) => default.apply(x1)
    };
    final def isDefinedAt(x1: K): Boolean = ((x1.asInstanceOf[K]: K): K @unchecked) match {
      case (k @ _) if k.prop => true
      case (defaultCase$ @ _) => false
    }
  };
  new $anonfun()
}: PartialFunction[K,String]))

In A1 <: K, the TypeTree for <: K has a non-null orig, so it passes here: https://github.com/scala/scala/blob/v2.13.14/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala#L1541-L1542.

Same for the K @unchecked type trees.

synthesizePartialFunction generates untyped untyped trees and calls the typer on them, so the originals are there.

Maybe we can catch isSynthetic of some symbol along the way before we get there. The $anonfun symbol is syntehtic. The applyOrElse / isDefinedAt are not.

@lrytz lrytz added this to the Backlog milestone May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant