-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Companion module should be deprecated if class is deprecated #12706
Comments
I think Scala 2 is at fault here. If the class is deprecated, the companion is not deprecated. It's only the warnings that get erroneously silenced. Actually that allows to create holes in the deprecation chain: >scala -deprecation
Welcome to Scala 2.13.4 (OpenJDK 64-Bit Server VM, Java 1.8.0_222).
Type in expressions for evaluation. Or try :help.
scala> @deprecated("class is deprecated", "1.0.0") class Foo; object Foo { def bar: Int = 42 }
class Foo
object Foo
scala> new Foo()
^
warning: class Foo is deprecated (since 1.0.0): class is deprecated
val res0: Foo = Foo@70c491b8
scala> Foo.bar
val res1: Int = 42
scala> @deprecated("class is deprecated", "1.0.0") class Foobar; object Foobar { def bar: Int = { new Foo(); 42 } }
class Foobar
object Foobar
scala> Foobar.bar
val res2: Int = 42 Observe that:
So Scala 3 does the right thing here. Scala 2 is to blame. |
Should we close this then? |
I agree the behavior is dubious. |
Compiler version
3.0.0
Minimized code
Output
Expectation
In Scala 2, companion is deprecated if class is. No warning is emitted.
That was for scala/bug#2799 which is currently #11022.
Extending a deprecated class is not an exemption:
Arguably, extending a deprecated class should also suppress deprecations. If I'm not supposed to extend, then it should be marked
@deprecatedInheritance
. (It's not outlandish that a base class is deprecated, for removal, but the subclass is not.)The text was updated successfully, but these errors were encountered: