-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support -Wconf and @nowarn #12857
Support -Wconf and @nowarn #12857
Conversation
cad24a9
to
2ca3ade
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, this is finally green. @smarter would you mind looking over this first draft? The diff is not that big.
Feature suggestions are very welcome. What I saw actually in use in Scala 2:
- filter by warning site (the fully qualified path to the location where the warning is emitted). this would requrie going through the
warning(..)
calls in the compiler and add thesite
parameter (in phases that have a typer we can probably take it from the context). - filter by more categories (currently, this PR has only has deprecations and feature warnings). this would also require adjusting all
warning(..)
calls in the compiler to add the category. - filter deprecations by
origin
, i.e. fully qualified path to the deprecated symbol
I'll add more tests, but first would like to know: how can I test compiler warnings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a quick look but I don't think I'll have the time to review this thoroughly.
Feature suggestions are very welcome.
I think it'd be great to be able to refer to messages by their name in https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala (minus the ID suffix) to have a stable identifier for them instead of having to use regexps.
how can I test compiler warnings?
With a .check file in a neg test, though that requires at least one error in the test or -Xfatal-warnings to be enabled (like in tests/neg-custom-args/fatal-warnings
)
Someone's twitter joke made me think It encourages boosting warnings to errors instead of suppressing warnings. Now I wonder if |
Also worth advertising |
2633fb5
to
ce64c43
Compare
I added filtering by message ID (
We could add a
Using the error ID works, but it's not great because reading the config later ( |
Pushed a few more changes. In "verbose" mode warnings are printed with a list of matching message filters that can be used in
Verbose mode can be enabled in However, changing compiler flags is slow. To make the workflow more convenient verbose mode can be enabled by (temporarily) annotating the surrounding code with
|
Also added filtering by the warning's compiler-internal
|
Very nice solution! Seems like if we support name=... we could even drop support for id=... since the latter would be much more cryptic, but we should document at the top of ErrorMessageID that the names shouldn't be changed. |
Some people might like it as it's more compact, but I'm happy to remove it and see if anyone asks for it.
The same idea would actually work very well as an alternative to the I vaguely remember @odersky criticizing the overhead of the |
Added a warning for |
I'm not sure this is a good idea. If users have a common codebase for Scala 2 and 3 with a false warning they want to remove in Scala 2 that does not exist in Scala 3, then this makes everything more difficult for them. |
That's why it's not enabled by default, only with |
Pushed a few more tests. I'm done with this PR from my side, not planning to push more changes until reviewers chime in. |
(updated the PR description) |
can this be merged? |
I think we can merge this unless @smarter or @som-snytt have any remarks |
Sorry I haven't had a chance to dig into |
@lrytz as this PR deserved the |
Sure, I updated the PR description. The first 3 sentences can go into the release notes. |
Thanks @lrytz |
I won't have time for further input now. I'll try to contribute on an ongoing basis to support this important feature. Thanks! |
@som-snytt what feature do you mean? Anyway, if this is just a feature, wouldn't it make sense to merge the current solution and introduce any improvements later? |
@prolativ yes, that's what he means. |
@lrytz it would be nice if you could squash your commits before merging (preferably into one unless there's a good reason to have a few) |
Sure, I can, but I thought this was usually not done in this repo? |
As far as I can see this is not strictly enforced to have 1 commit per PR but reasonable squashing makes git history easier to read. At the same time we would like to preserve merge commits to manage the release process more easily |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
…& 2.13 in `Compile` TODO enable -Xfatal-warnings for scala3 when this is RELEASED: scala/scala3#12857
Is there any reason why the edit: made a feature request for this: #17634 |
@lrytz, would you be available to also update the migration guide to mention that |
This PR adds a
-Wconf
compiler flag that allows filtering and configuring compiler warnings (silence them, or turn them into errors).It also integrates the fantastic silencer compiler plugin by @ghik into the compiler, which allows suppressing warnings locally using the @nowarn annotation.
-Wconf
and@nowarn
work largely the same way as in Scala 2, but most filters for selecting warnings are different. The output of-Wconf:help
gives more details:Note that Scala 2 supports many other filters. This PR delivers a good starting point for Scala 3 and we should wait and see if users actually want other filters.
Co-authored by @som-snytt.
Fixes #8908
Other changes in this PR
-Wunused
flag, for now only with-Wunused:nowarn
(and-Wunused:all
). I assume that (long-term) migrating the other unused warnings from Scala 2 is desired.-unchecked
flag was previously unused, unchecked warnings were reported as normal warnings. Now unchecked warnings are reported as such, and-unchecked
is enabled by default (as in Scala 2).neg
compilation tests, warnings are now emitted and represented in.check
files.