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 in pattern #12997

Open
lrytz opened this issue May 17, 2024 · 1 comment
Open

Spurious deprecation warning in pattern #12997

lrytz opened this issue May 17, 2024 · 1 comment
Milestone

Comments

@lrytz
Copy link
Member

lrytz commented May 17, 2024

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.

image
@lrytz lrytz added this to the Backlog milestone May 17, 2024
@som-snytt
Copy link

som-snytt commented May 17, 2024

$ 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.)

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

2 participants