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

scalac warns about deprecated use of identifier "then" even if it is marked as deprecated #5715

Closed
scabug opened this issue Apr 27, 2012 · 7 comments · Fixed by scala/scala#9960

Comments

@scabug
Copy link

scabug commented Apr 27, 2012

In the following source code

    @deprecated("Use Then instead of then", "0.10.0-M2")
    def then[B : BaseTypeMapper](res: Column[B]) = Then(res)

scalac complains that

C:\Users\szeiger\code\scala-query\src\main\scala\scala\slick\ql\Case.scala:28: then is now a reserved word; usage as an identifier is deprecated
    def then[B : BaseTypeMapper](res: Column[B]) = Then(res)
        ^

This is not usually the case when using deprecated API. If the caller is also deprecated, no warning should be emitted.

@scabug
Copy link
Author

scabug commented Apr 27, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5715?orig=1
Reporter: @szeiger
Affected Versions: 2.10.0-M3

@scabug
Copy link
Author

scabug commented May 3, 2012

@paulp said:
This is actually tricky to deal with, because we need to warn on then but not then (I don't know if jira will savage my backticks) and that information is discarded before annotations are processed.

@magnolia-k
Copy link

Warnings about reserved words are given in the lexical analysis stage(src/compiler/scala/tools/nsc/ast/parser/Scanners.scala ). Therefore, warnings are displayed in all places where they appear as identifiers.

Isn't it enough to issue warnings at the time of identifier declaration?

package example

class then

object Foo {
  val t = new then
}
[info] compiling 1 Scala source to /xxx/scala-seed-project/target/scala-2.13/classes ...
[warn] /xxx/scala-seed-project/src/main/scala/example/Hello.scala:3:7: then is a reserved word (since 2.10.0); usage as an identifier is deprecated
[warn] class then
[warn]       ^
[warn] /xxx/scala-seed-project/src/main/scala/example/Hello.scala:6:15: then is a reserved word (since 2.10.0); usage as an identifier is deprecated
[warn]   val t = new then
[warn]               ^
[warn] two warnings found

With the release of Scala3, reserved words have already been fixed, and reserved words other than then have been added.

Therefore, it would be better to remove the warning about future reserved words in the lexical analysis stage, and change it to warn against reserved words other than then, which were added in Scala3, only when declaring identifiers.

@SethTisue
Copy link
Member

it would be better to remove the warning about future reserved words in the lexical analysis stage

agree; I would be in favor of merging a PR that did only that

and as a separate matter, if new warnings are added, I'd suggest putting those warnings behind -Xsource:3

@som-snytt
Copy link

som-snytt commented Jul 13, 2021

It could be done via the much-abused "extra units of work" that run after typer.

Edit: I had a branch from 2019 that started down that path.

@som-snytt
Copy link

new then

should be

new `then`

that is, if we were still using new.

These warnings already go through runReporting, so -Wconf works.

Normally, Refchecks checks deprecated usage. It could also do the name check, as an Ident now knows if it was backticked.

For the definition, typer could clear buffered deprecations in range of the deprecated definition.

@som-snytt
Copy link

The future keywords warning was at scala/scala#9722.

My first take removed the current warning at scanner, added the usage warning in refchecks (check the name when the ref is checked) and the definition site warning piggy-backing on the future keywords warning in parser.

My second take piggybacks on -Wconf/nowarn to emit a Suppression when deprecations are seen, the equivalent of @nowarn(cat=deprecation) but does not trigger unused warning. (But the deprecation from scanner doesn't get site and origin for advanced -Wconfing.)

The hard part on first take was figuring out who was stripping the isBackquoted attachment. (It was the conversion to type name.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants