bug
bug copied to clipboard
Spurious deprecation warning in pattern
Spurious deprecation warning when the type of a bound value in a pattern is deprecated.
Scala 2.13.14:
scala> @deprecated class K
class K
scala> def k = Option(new K)
^
warning: class K is deprecated
def k: Option[K]
scala> def t = k match { case Some(the_k) => 0; case _ => 1 }
^
warning: class K is deprecated
def t: Int
the case Some(the_k) tree is transformed to case (value: K): Some[K]((the_k @ _)) => 0 where the (value: K): Some[K] tree is a TypeTree with a MethodType. The reference to K in there is reported by RefChecks.
$ scala -deprecation
Welcome to Scala 3.4.1 (21.0.2, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> @deprecated class K
// defined class K
scala> val k = Some(new K)
1 warning found
-- Deprecation Warning: ------------------------------------------------------------------------------------------------
1 |val k = Some(new K)
| ^
| class K is deprecated
val k: Some[K] = Some(rs$line$1$K@5e7e7a7e)
scala> k match { case Some(v) => v }
1 warning found
-- Deprecation Warning: ------------------------------------------------------------------------------------------------
1 |k match { case Some(v) => v }
| ^
| class K is deprecated
val res0: K = K@5e7e7a7e
scala>
without -deprecation the summary is
scala> val k = Some(new K)
there were 2 deprecation warnings; re-run with -deprecation for details
1 warning found
val k: Some[K] = Some(rs$line$1$K@7e1762e6)
The spec talks only about the expected type of the variable pattern. (It is not specified as a typed pattern.)