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

-Wunused:imports false negative for redundant or spurious import #21809

Open
som-snytt opened this issue Oct 19, 2024 · 0 comments
Open

-Wunused:imports false negative for redundant or spurious import #21809

som-snytt opened this issue Oct 19, 2024 · 0 comments
Assignees
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug

Comments

@som-snytt
Copy link
Contributor

Compiler version

3.5.1

Minimized code

package p {
  package q {
    import q.*
    class Test {
      override def toString = new C().toString + " for Test"
    }
  }
}
package q {
  class C {
    override def toString = "q.C"
  }
}

Output

➜  snips scala compile --server=false -S 2.13.15 -Xsource:3-cross -Wunused packaging.scala
/home/amarki/snips/packaging.scala:6: error: not found: type C
      override def toString = new C().toString + " for Test"
                                  ^
/home/amarki/snips/packaging.scala:4: warning: Unused import
    import q.*
             ^
1 warning
1 error
Compilation failed
➜  snips scala compile --server=false -Wunused:all packaging.scala
-- [E006] Not Found Error: /home/amarki/snips/packaging.scala:6:34 -----------------------------------------------------
6 |      override def toString = new C().toString + " for Test"
  |                                  ^
  |                                  Not found: type C
  |
  | longer explanation available when compiling with `-explain`
1 error found
Compilation failed

Expectation

I refactored a test package from package p to

package test.p
import p.*

(in order to test public API) and was pleased that I didn't have to write import _root_.p.*.

As expected, with nested packages, the import sees the nested p.q. However, I also expected some indication that my import is spurious.

I know that importing is generous, so that if an import and definition resolve to the same symbol, it won't annoy me with cautionary messages. But I'd like a way to ask for warnings.

Scala 2 knows that the import is unused, but Scala 3 is willing to take it as used.

@som-snytt som-snytt added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label 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 Oct 19, 2024
@som-snytt som-snytt self-assigned this Oct 19, 2024
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

No branches or pull requests

1 participant