Skip to content

Show nowarn / Wconf filters for a warning with @nowarn("verbose")#10985

Merged
lrytz merged 1 commit into
scala:2.13.xfrom
lrytz:nowarnV
Jan 30, 2025
Merged

Show nowarn / Wconf filters for a warning with @nowarn("verbose")#10985
lrytz merged 1 commit into
scala:2.13.xfrom
lrytz:nowarnV

Conversation

@lrytz

@lrytz lrytz commented Jan 20, 2025

Copy link
Copy Markdown
Member

This is a practical method to find out what filter can be applied to silence a warning, no need to modify the compiler flags in the build configuration.

Same as already implemented in Scala 3.

scala> @nowarn("v") def f = try 1
                            ^
       warning: A try without a catch or finally is equivalent to putting its body in a block; no exceptions are handled.
       Applicable -Wconf / @nowarn filters for this warning: msg=<part of the message>, cat=other, site=f
def f: Int

(https://hachyderm.io/@spills/112831541923471812)

@lrytz lrytz requested a review from som-snytt January 20, 2025 10:56
@scala-jenkins scala-jenkins added this to the 2.13.17 milestone Jan 20, 2025
@som-snytt

Copy link
Copy Markdown
Contributor

That is so cool! TIL! and I just made a tweak on dotty about nowarn and didn't notice.

Not that I didn't believe you, but I had to try it out on my test file.

  |            unused explicit parameter
Matching filters for @nowarn or -Wconf:
  - id=E198
  - name=UnusedSymbol

@som-snytt som-snytt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize innovations were propagating in this direction.

It's very nice when similarity of code makes porting and reviews easier or possible.

Comment thread src/library/scala/annotation/nowarn.scala Outdated
@som-snytt

Copy link
Copy Markdown
Contributor

Every code base should have class dowarn extends nowarn("v").

That doesn't work yet.

@lrytz

lrytz commented Jan 20, 2025

Copy link
Copy Markdown
Member Author

Changing compiler flags is much more tedious than adding an annotation to the source and rebuilding.

Scala 3 -explain is an obvious candidate.

For Scala 2, I looked through the settings. Scoped -Vprint would cool, maybe -Vtyper too, but both are for advanced users. -Vcyclic is a global flag, I don't think an annotation would work for that.

So maybe -explain is the only real opportunity. I'll create a ticket to see if they like the idea, if they want to reuse @nowarn("v") for that, or some new annotation.

As already implemented in Scala 3

```
scala> @nowarn("v") def f = try 1
                            ^
       warning: A try without a catch or finally is equivalent to putting its body in a block; no exceptions are handled.
       Applicable -Wconf / @nowarn filters for this warning: msg=<part of the message>, cat=other, site=f
def f: Int
```
@som-snytt

Copy link
Copy Markdown
Contributor

flags vs annotations is sad but true. Also counter-intuitive from an old school perspective. Modifying source is heavyweight, but because of the "build tool", flipping an option is heavier.

I don't use an IDE, although previously I used Eclipse for Java projects, but I can see the "local" use case: there is some weirdness in my code, it shows a red squiggle or perhaps amber, I want to click an icon to show what I can do to silence the squiggle.

That workflow is entirely local.

The missing piece is still an audit to tell me what warnings were modified (locally suppressed) in my code.

@lrytz lrytz added the release-notes worth highlighting in next release notes label Jan 23, 2025
@lrytz lrytz merged commit a7af6f2 into scala:2.13.x Jan 30, 2025
hamzaremmal pushed a commit to hamzaremmal/scala3 that referenced this pull request May 2, 2025
Show nowarn / Wconf filters for a warning with  @nowarn("verbose")
hamzaremmal pushed a commit to scala/scala3 that referenced this pull request May 7, 2025
Show nowarn / Wconf filters for a warning with  @nowarn("verbose")
@lrytz lrytz changed the title Show nowarn / Wconf filters for a warning with @nowarn("verbose") Show nowarn / Wconf filters for a warning with @nowarn("verbose") Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes worth highlighting in next release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants