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

Fix -Wunused:import registering constructor ("<init>") instead of its owner (also fix false positive for enum) #16661

Merged
merged 3 commits into from
Jan 12, 2023

Conversation

PaulCoral
Copy link
Contributor

@PaulCoral PaulCoral commented Jan 11, 2023

This solves the issue #16650.

The issue is that member(sym.name) failed to resolve when a type contains multiple identical name. Here the dotty.tools.dotc.util package contains multiple "" (constructor), so member fail to resolve the name

The solution is to register the owner of the contructor instead of the constructor itself.

⚠️ I couldn't create a test where this appends, I tested it by publishLocal and testing the code in a different project with this code from #16650 (also didn't check on the metals build):

//> using lib "org.scala-lang::scala3-compiler:3.3.0-RC1-bin-20230109-f56089b-NIGHTLY"
//> using scala "3.3.0-RC1-bin-20230109-f56089b-NIGHTLY"
//> using option "-Wunused:all"

import dotty.tools.dotc.util.LinearSet

@main
def run = 
  val a = 123
  println("Hello!")
sbt> run
[info] compiling 1 Scala source to .../target/scala-3.3.0-RC1-bin-SNAPSHOT/classes ...
[warn] -- Warning: ..../src/main/scala/Main.scala:5:29 
[warn] 5 |import dotty.tools.dotc.util.LinearSet
[warn]   |                             ^^^^^^^^^
[warn]   |                             unused import
[warn] -- Warning:.../src/main/scala/Main.scala:10:6 
[warn] 10 |  val a = 123
[warn]    |      ^
[warn]    |      unused local definition
[warn] two warnings found
[info] running run 
Hello!

EDIT

Also add a related fix for import generated by enum (false positive)

PaulCoral and others added 2 commits January 11, 2023 11:52
- Register owner of the constructor instead of the constructor.
- This solves the issue where `member(sym.name)` have multiple identical
  names
@Kordyjan Kordyjan requested a review from szymon-rd January 11, 2023 11:02
@Kordyjan Kordyjan added this to the 3.3.0-RC1 milestone Jan 11, 2023
@PaulCoral PaulCoral marked this pull request as ready for review January 11, 2023 11:49
- Some enum generates an import clause for its cases
- Update some test suits
@PaulCoral
Copy link
Contributor Author

PaulCoral commented Jan 11, 2023

Added a small fix also related to -Wunused:import issue (false positive enum). fa1d2bb

Copy link
Contributor

@szymon-rd szymon-rd left a comment

Choose a reason for hiding this comment

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

I wasn't able to come up with a reproduction that we could run with vulpix. I managed to get rid of the compiler dependency but there still has to be a jar file for this to crash: #16666. Let's wait another day and see if somebody has something to say there, if there is no development I think we will have to merge it without a regression test. Otherwise, all looks good to me!

@PaulCoral PaulCoral changed the title Fix -Wunused:import registering constructor ("<init>") instead of its owner Fix -Wunused:import registering constructor ("<init>") instead of its owner (also fix false positive for enum) Jan 12, 2023
@szymon-rd
Copy link
Contributor

It's ok to merge IMO given that we found the core problem and have a way to address it.

@PaulCoral
Copy link
Contributor Author

It's ok to merge IMO given that we found the core problem and have a way to address it.

Also the additional fix for enums is important at it fixes a common cause of false positive.

@szymon-rd szymon-rd merged commit 483b1e8 into scala:main Jan 12, 2023
@PaulCoral PaulCoral deleted the fix/linter/unused_import branch June 8, 2023 19:49
@Kordyjan Kordyjan modified the milestones: 3.3.0-RC1, 3.3.0 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants