-
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
[Semester Project] Add new front-end phase for unused entities and add support for unused imports #16157
Conversation
- report unused named import - no given or wildcard import - issue with method reference (e.g. apply, factory, ...)
Emits a warning when none of element of a wildcard ('_') import is used (i.e. a "unused import" warning).
- Add various tests for unused warnings - Fix warning not emitted when imported object is used another scope
- Emit warning for unused given imports - Emit warning for wildcard imports when only given instances are used. ``` import SomeGivenImports.given // OK import SomeGivenImports._ // error ```
Have you looked at #14524 where "used" means looked up. The Scala 2 experience was that deciding what is unused is complicated by desugarings. I don't know if that will be the case for Scala 3. For imports, especially, it was simple to record the look-up. For example, deciding if a language import is used. (Scala 2 was also complicated by interactions with macros.) |
@som-snytt |
- Add an `isRunnable` methode to the `CheckUnused` phase to avoid unecessary costly checks (suggested by @bishabosha) - Move neg compilation tests out of folder
Very excited to see some activity on this! Thank you for working on it, and thanks to @som-snytt for pioneering the effort. The lack of |
- Do not emit any warning for import exclusion. - These are hard to interpret. These can be placed on purpose to avoid future usage of a symbol.
- Add a compiler settings for unused local definition - Add check for unused local variable in CheckUnused phase - Add some "neg-custom-args/fatal-warnings" checks for unused locals definition
- Add the "privates" option for "-Wunused" - Implement "unused privates member" checks in "CheckUnused" phase - Add a test suit for the previous point
This looks interesting. I would like it if there was a way to obtain the explicit list of used imports (not including the unused ones), so that it can be written out to a file for analysis by external tooling. There is precedent to do this in Haskell's ghc compiler and it leads to an improved UX for users. |
🚀 woo! Great job on this @PaulCoral! |
Thanks @szymon-rd, @lrytz and everyone else involved for reviews, hints and suggestions and also @som-snytt for the very helpful previous work. |
Thanks @PaulCoral! |
Great work! I am happy to see this turned out so well. |
This is so important for me. Linting was the major blocker of full migration to Dotty. Many thanks to @PaulCoral and everyone else involved! |
Ok, there is a problem, probably with this PR: |
I absolutely can't wait to use this. Thanks! |
Looks like we have the flag leftover and it was ignored until now, but seems to fail with the specific repo. |
You've probably covered this already, but make sure that the logic correctly handles imports that are used to enable features or suppress warnings, such as A lack of references to the simple name made visible by such a flagging import (e.g., I don't know exactly how "use" of such flagging imports should be defined. For example, should an (Note how the |
Yeah, now I see that this PR is already merged. I thought I was looking at a page for a PR or issue that was still open. |
This PR, related to my semester project #15503 on adding dotty's linter features, adds the following:
CheckUnused
front-end phase, which will check the the tree produced by the typer, for unused entites (imports, local defs, ...)-Wunused:imports
including given imports and wildcard imports-Wunused:locals
-Wunused:privates
-Wunused:params
Emit warning for-Wunused:patvars
-Wunused:unsafe-warn-patvars
-Wunused:linted
-Wunused
-Wunused:givens
alias to-Wunused:implicits
Here are a few examples:
Unused Imports
Unused local definitions
Unused private members
Unused parameters
Unused pattern variables
Please check the test file for the handled cases.
@odersky
@anatoliykmetyuk