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

deprecation option is defined incorrectly #5

Closed
satorg opened this issue Sep 14, 2022 · 14 comments
Closed

deprecation option is defined incorrectly #5

satorg opened this issue Sep 14, 2022 · 14 comments

Comments

@satorg
Copy link
Contributor

satorg commented Sep 14, 2022

val deprecation = ScalacOption(
"-deprecation",
version => version < V2_13_0 || version >= V3_0_0
)

leads to

scala> ScalacOptions.deprecation.isSupported(ScalaVersion.V2_12_5)
res3: Boolean = true

scala> ScalacOptions.deprecation.isSupported(ScalaVersion.V2_13_6)
res4: Boolean = false

scala> ScalacOptions.deprecation.isSupported(ScalaVersion.V3_0_0)
res5: Boolean = true

Apparently, the -deprecation compiler option is supported on v2.13.x pretty well:

$ scala-cli compile -S 2.13.6 -O -help
Usage: scalac <options> <source files>

Standard options:
  ...
  -deprecation                 Emit warning and location for usages of deprecated APIs. See also -Wconf. [false]
  ...

So I wonder – is it defined as unsupported in 2.13.x for a reason or by a mistake?

@satorg
Copy link
Contributor Author

satorg commented Sep 14, 2022

@DavidGregory084 @armanbilge could you clarify please?

@DavidGregory084
Copy link
Member

DavidGregory084 commented Sep 14, 2022

@satorg yes that's correct, however it's my understanding that the -deprecation option was replaced by the -Xlint:deprecation option in 2.13.x, so sbt-tpolecat (and as a result scalac-options) usually enables that instead.

It's possible that I got the wrong idea and those two options do something different, but if so the scalac documentation doesn't really make that clear.

@satorg
Copy link
Contributor Author

satorg commented Sep 14, 2022

but if so the scalac documentation doesn't really make that clear.

yeah, seems it almost never does :)

@satorg
Copy link
Contributor Author

satorg commented Sep 14, 2022

@DavidGregory084 regarding -Xlint:deprecation:
Appears it was added to 2.12 as well since 2.12.13:

$ scala-cli compile -S 2.12.12 -O -Xlint:deprecation dummy.scala 
Compiling project (Scala 2.12.12, JVM)
Error: 'deprecation' is not a valid choice for '-Xlint'
Compiled project (Scala 2.12.12, JVM)

whereas

$ scala-cli compile -S 2.12.13 -O -Xlint:deprecation dummy.scala 

compiles fine.

@satorg
Copy link
Contributor Author

satorg commented Sep 14, 2022

I would suppose that -deprecation and -Xlint:deprecation are slightly different options.
At least according to help from the compiler:
scalac -help says that

-deprecation — Emit warning and location for usages of deprecated APIs. See also -Wconf. [false]

whereas scalac -Xlint:help returns

deprecation — Enable -deprecation and also check @deprecated annotations.

I.e. I would guess, it was supposed that -Xlint:deprecation implies -deprecation with some additional functionality.
But I'm not getting what is the difference exactly...

@SethTisue
Copy link
Member

sounds like something @som-snytt might know

@som-snytt
Copy link

The additional juice is

Welcome to Scala 2.13.8 (OpenJDK 64-Bit Server VM, Java 18.0.2.1).
Type in expressions for evaluation. Or try :help.

scala> @deprecated("old stuff") def f = 42
def f: Int

scala> :replay -Xlint
replay> @deprecated("old stuff") def f = 42
         ^
        warning: Specify both message and version: @deprecated("message", since = "1.0")
def f: Int


scala>

Otherwise, -Xlint:deprecation just enables -deprecation, which in turn enables or disables -Wconf:cat=deprecation!

You need -deprecation:false to disable; -Xlint:-deprecation is not sufficient; it's intended that "grouped" options don't override other settings.

scala> :replay -Xlint:-deprecation
replay> @deprecated("old stuff") def f = 42
def f: Int

replay> f
        f
        ^
On line 2: warning: method f is deprecated: old stuff
def f: Int
val res0: Int = 42


scala> :replay -deprecation:false
replay> @deprecated("old stuff") def f = 42
def f: Int

replay> f
def f: Int
val res0: Int = 42


scala>

Javac also migrated -deprecation to -Xlint (see javac --help-lint). Obviously, scalac steals all of javac's greatest innovations.

@som-snytt
Copy link

Worth adding that -deprecation is not deprecated, but -Xlint is recommended by definition.

@satorg
Copy link
Contributor Author

satorg commented Sep 14, 2022

That helps a lot, thank you!

@satorg
Copy link
Contributor Author

satorg commented Sep 14, 2022

Also I realized that starting with Scala 2.12.13 the -deprecation option begins behaving differently (comparing to previous Scala versions):

Scala 2.12.12:

$ scala-cli -S 2.12.12 -O -deprecation
...

scala> @deprecated("old stuff") def f = 42
<console>:11: warning: @deprecated now takes two arguments; see the scaladoc.
       @deprecated("old stuff") def f = 42
        ^
f: Int

scala> f
<console>:13: warning: method f is deprecated: old stuff
       f
       ^
res0: Int = 42

scala> :replay -Xlint:deprecation
'deprecation' is not a valid choice for '-Xlint'
Replaying: @deprecated("old stuff") def f = 42
<console>:11: warning: @deprecated now takes two arguments; see the scaladoc.
       @deprecated("old stuff") def f = 42
        ^
f: Int

Replaying: f
<console>:13: warning: method f is deprecated: old stuff
       f
       ^
res0: Int = 42

Now compare to
Scala 2.12.13:

$ scala-cli -S 2.12.13 -O -deprecation
...

scala> @deprecated("old stuff") def f = 42
f: Int

scala> f
<console>:13: warning: method f is deprecated: old stuff
f
^
res0: Int = 42

scala> :replay -Xlint:deprecation
Replaying: @deprecated("old stuff") def f = 42
<console>:11: warning: Specify both message and version: @deprecated("message", since = "1.0")
@deprecated("old stuff") def f = 42
 ^
f: Int

Replaying: f
<console>:13: warning: method f is deprecated: old stuff
f
^
res0: Int = 42

i.e. in Scala 2.12.12 -deprecation behaves similar to -Xlint:deprecation in newer versions whereas the latter is not supported. But starting with Scala 2.12.13 the latter becomes supported whereas "good old" -deprecation becomes less capable and stops checking the @deprecated annotation itself. 🤔

@som-snytt
Copy link

som-snytt commented Sep 14, 2022

That warning was added by a deprecation zealot. It would always warn without any option. Also the message is annoying and unhelpful. see the scaladoc.

I think annoying things should be opt-in, like marriage and paid labor.

@DavidGregory084
Copy link
Member

@satorg on the basis of @som-snytt's explanation, do you think there is anything to do here? Perhaps we should fine-tune the version ranges for these two options a bit?

@satorg
Copy link
Contributor Author

satorg commented Sep 14, 2022

@DavidGregory084 , yes, short-term we could just tune the version ranges, I think. I can file a PR, if you don't mind.

I am quite uncertain though whether we should limit -deprecation by the 2.12.12 version just because there is -Xlint:deprecation introduced in 2.12.13. In fact, -deprecation had not been discontinued by that version and still supported pretty well.

I mean, consider this case: if someone prefers using -deprecation but not -Xlint:deprecation for some reason (any reason, actually), then it will be reported as supported until 2.12.12 only. Then starting from 2.12.13 it becomes unsupported, and thus won't be rendered in the [2.12.13 - 3.0.0) versions range. Then starting with 3.0.0 it is supported again. Strictly speaking, it is not true – -deprecation is kept supporting through all the scalac versions. Therefore my concern is – should we suppress that option for those scalac versions that also have -Xlint:deprecation available?

So I would suggest to make -deprecation permanently supported instead – it shouldn't be harmful anyway, I think.
Or do you have concerns about it?

@satorg
Copy link
Contributor Author

satorg commented Sep 18, 2022

Resolved in #8

@satorg satorg closed this as completed Sep 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants