Skip to content

@annotation.nowarn ignored/lost during inlining #22672

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

Closed
MartinHH opened this issue Feb 27, 2025 · 2 comments · Fixed by #22682
Closed

@annotation.nowarn ignored/lost during inlining #22672

MartinHH opened this issue Feb 27, 2025 · 2 comments · Fixed by #22682
Assignees
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug
Milestone

Comments

@MartinHH
Copy link

Compiler version

3.6.3, 3.3.5 (and many others)

Minimized code

A minimal library (use scala publish local <first_filename> to publish it locally):

//> using scala "3.6.3"

//> using option "-Xfatal-warnings"

//> using publish.organization "io.bar.foo"
//> using publish.name "deprecation-bug-example"
//> using publish.version "0.0.1"

package io.bar.foo.example

@annotation.nowarn("cat=deprecation")
inline def dooFoo: String =
  val stream = Stream.empty
  stream.toString

Then a usage of that library:

//> using scala "3.6.3"

//> using dep "io.bar.foo::deprecation-bug-example::0.0.1"

val x = io.bar.foo.example.dooFoo

Use scala compile <second_filename> to compile it

Output

Compiling project (Scala 3.6.3, JVM (23))
Warning: there was 1 deprecation warning; re-run with -deprecation for details
Compiled project (Scala 3.6.3, JVM (23))

Expectation

No deprecation warning is emitted (as it is the case if dooFoo is not declared inline).

@MartinHH MartinHH added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 27, 2025
@MartinHH MartinHH changed the title @annotation.nowarn igored/lost during inlining @annotation.nowarn ignored/lost during inlining Feb 27, 2025
@som-snytt som-snytt added area:reporting Error reporting including formatting, implicit suggestions, etc and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 27, 2025
@som-snytt
Copy link
Contributor

som-snytt commented Feb 27, 2025

There are a few issues.

Taking a step back, it's not obvious that the expectation is correct. @nowarn is for "local warning suppression".

Inlining checks the "call site", so that inlining a deprecated method will warn.

CrossVersionChecks checks the expansion; the diagnostic is issued at the inlined position, which under separate compilation is not a current source. It would be more natural to see the warning at the non-inlined position, with an explanation that inlined code was involved. This may depend on a hypothetical option that selects how warnings and lints are applied to expanded code.

Apparently, it currently does not respect:

//> using option "-Werror"

Please note the correct spelling of the option to turn warnings into errors without using -Wconf:any:e.

$ scala-cli compile --server=false -S 3.6.3 -d ~/sandbox -cp ~/sandbox tests/warn/i22672/usage_2.scala
-- Deprecation Warning: lib_1.scala:11:2 ---------------------------------------
11 |  g
   |  ^
   |  method g in package p is deprecated since 1.0: old api
1 warning found

after adding a noninlined deprecation, it works (fails the compilation)

-- Deprecation Warning: /home/amarki/projects/dotty/tests/warn/i22672/usage_2.scala:11:14
11 |def failing = huh
   |              ^^^
   |method huh in package q is deprecated since 0.1: do I even know how it works
No warnings can be incurred under -Werror (or -Xfatal-warnings)
-- Deprecation Warning: lib_1.scala:11:2 ---------------------------------------
11 |  g
   |  ^
   |  method g in package p is deprecated since 1.0: old api
2 warnings found
1 error found
Compilation failed

To satisfy the expectation, inlining should inline the symbol's @nowarn at the inlined body. That sounds reasonable and doable.

But currently, annotating the inlined expression doesn't work (the annotations are collected in typer on a per-file basis).

-- Deprecation Warning: lib_1.scala:11:2 ---------------------------------------
11 |  g: @nowarn
   |  ^
   |  method g in package p is deprecated since 1.0: old api

I haven't checked yet if transparent inline conforms to expectations. (Edit: It correctly warns posttyper.)

@som-snytt
Copy link
Contributor

The PR uses any annotation it finds on the inline method or its body to "register" the suppression.

All positions are in terms of the inlined source.

@jchyb jchyb closed this as completed in ddc2b33 Mar 11, 2025
@WojciechMazur WojciechMazur added this to the 3.7.0 milestone Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants