@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]))
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.
Scala 2.13.14
The AST is
In
A1 <: K
, theTypeTree
for<: K
has a non-nullorig
, 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. TheapplyOrElse
/isDefinedAt
are not.