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

Some -Wnonunit-statement can't be silenced with @annotation.nowarn #17741

Closed
mrdziuban opened this issue May 31, 2023 · 2 comments · Fixed by #18089
Closed

Some -Wnonunit-statement can't be silenced with @annotation.nowarn #17741

mrdziuban opened this issue May 31, 2023 · 2 comments · Fixed by #18089
Assignees
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug

Comments

@mrdziuban
Copy link

Compiler version

3.3.1-RC1

Minimized code

<foo>bar</foo>: @annotation.nowarn("msg=unused value")

Output

-- [E176] Potential Issue Error: test.scala:1:5 --------------
1 |  <foo>bar</foo>: @annotation.nowarn("msg=unused value")
  |       ^
  |       unused value of type xml.NodeBuffer

Expectation

The nowarn annotation should silence the warning. I've also tried using a -Wconf compiler option but still no luck.

I said "some" in the title because the issue doesn't happen for all non-Unit statements. I initially came across it with XML-literals in my code and found that it doesn't happen for other simple statements, e.g. this works properly

scala.util.Try(1): @annotation.nowarn("msg=unused value")
@mrdziuban mrdziuban added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 31, 2023
@jchyb
Copy link
Contributor

jchyb commented May 31, 2023

This appears to be closely related to #17735 (-Wnonunit-statements reuses some -Wvalue-discard logic, as I understand it)

Here, the annotation also stops working only when -Xfatal-warnings is used, but works correctly otherwise. scala-cli minimization (with a dependency):

//> using scala "3.3.1-RC1"
//> using dep "org.scala-lang.modules::scala-xml:2.1.0"
//> using option "-Wnonunit-statement", "-Xfatal-warnings"
def example() = 
  <foo>bar</foo>: @annotation.nowarn("msg=unused value")

@jchyb jchyb 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 May 31, 2023
@amumurst
Copy link

amumurst commented Jun 1, 2023

Also ran into this with scala-xml. I don't really see why it should be giving a warning at all and would consider it a bug too.

@KacperFKorban KacperFKorban self-assigned this Jun 7, 2023
KacperFKorban referenced this issue in dotty-staging/dotty Jun 28, 2023
…ng it into an error

closes lampepfl#17741
closes lampepfl#17735
@dwijnand dwijnand changed the title Some -Wnonunit-statements can't be silenced with @annotation.nowarn Some -Wnonunit-statement can't be silenced with @annotation.nowarn Jun 29, 2023
KacperFKorban referenced this issue in dotty-staging/dotty Jun 29, 2023
…ng it into an error

closes lampepfl#17741
closes lampepfl#17735
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
4 participants