Skip to content

Wunused:imports false positive, wrong import scope #21917

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

Closed
gaelrenoux opened this issue Nov 10, 2024 · 1 comment · Fixed by #20894
Closed

Wunused:imports false positive, wrong import scope #21917

gaelrenoux opened this issue Nov 10, 2024 · 1 comment · Fixed by #20894
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug

Comments

@gaelrenoux
Copy link

Compiler version

3.5.2

Minimized code

import Dog.Owner

class Dog(owner: Owner) {
  import Dog.*
  
  val getOwner: Owner = owner
}

object Dog {
  class Owner
}

Output

[warn] -- [E198] Unused Symbol Warning: /home/gael/Repositories/Gael/bug-reproduction/import-failure/src/main/scala/Dog.scala:1:11 
[warn] 1 |import Dog.Owner
[warn]   |           ^^^^^
[warn]   |           unused import
[warn] one warning found

Expectation

Import should not be reported. Removing the import makes the compilation fail, as expected. Removing the internal import import Dog.* makes the message disappear.

@gaelrenoux gaelrenoux added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 10, 2024
@gaelrenoux gaelrenoux changed the title Wunused:imports false positive, messed import scope Wunused:imports false positive, wrong import scope Nov 10, 2024
@som-snytt som-snytt added area:linting Linting warnings enabled with -W or -Xlint and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 10, 2024
@som-snytt som-snytt self-assigned this Nov 10, 2024
@som-snytt
Copy link
Contributor

som-snytt commented Jan 2, 2025

The "inner" import may be deemed unused; it is not ambiguous because it resolves the same symbol as the "outer" import.

In the PR, there are no nesting levels, so it picks the highest precedence binding, assuming correctness.

(An inner import Car.* would be erroneous, for example.)

Scala 2 does not warn because the compiler marks the inner import as used after reconciling with the outer import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants