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

Renaming specialized on import results in "unused import" warnings #20536

Closed
satorg opened this issue Jun 8, 2024 · 3 comments · Fixed by #20549
Closed

Renaming specialized on import results in "unused import" warnings #20536

satorg opened this issue Jun 8, 2024 · 3 comments · Fixed by #20549
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug
Milestone

Comments

@satorg
Copy link

satorg commented Jun 8, 2024

Compiler version

v3.3.3, v3.4.2

Minimized code

import scala.{specialized => sp}

trait ImportUnusedSpecializedRename[@sp Int]

Script that I used for testing:

set -v

scala-cli clean ImportUnusedSpecializedRename.scala

scala-cli compile --server=false -j 17 -S 2.12.19 -Xlint:unused ImportUnusedSpecializedRename.scala
scala-cli compile --server=false -j 17 -S 2.13.14 -Wunused ImportUnusedSpecializedRename.scala
scala-cli compile --server=false -j 17 -S 3.3.3 -Wunused:imports ImportUnusedSpecializedRename.scala
scala-cli compile --server=false -j 17 -S 3.4.2 -Wunused:imports ImportUnusedSpecializedRename.scala

Output

scala-cli clean ImportUnusedSpecializedRename.scala

scala-cli compile --server=false -j 17 -S 2.12.19 -Xlint:unused ImportUnusedSpecializedRename.scala
scala-cli compile --server=false -j 17 -S 2.13.14 -Wunused ImportUnusedSpecializedRename.scala
scala-cli compile --server=false -j 17 -S 3.3.3 -Wunused:imports ImportUnusedSpecializedRename.scala
-- Warning: /Users/.../ImportUnusedSpecializedRename.scala:1:26 
1 |import scala.{specialized => sp}
  |              ^^^^^^^^^^^^^^^^^
  |              unused import
1 warning found
scala-cli compile --server=false -j 17 -S 3.4.2 -Wunused:imports ImportUnusedSpecializedRename.scala
-- Warning: /Users/.../ImportUnusedSpecializedRename.scala:1:26 
1 |import scala.{specialized => sp}
  |              ^^^^^^^^^^^^^^^^^
  |              unused import
1 warning found

Expectation

Scala3 should compile the above example without the "unused import" warnings.
As long as Scala2 compilers can do.

Additional Information

This issues causes a lot of extra warnings added up while compiling Cats for Scala3.
Historically, Cats uses import scala.{specialized => sp} in a bunch of files across the repository.

@som-snytt
Copy link
Contributor

The Scala 3 check was intentionally skipping the type parameter, but inadvertently skipping the annotation.

The rename was not germane.

Worth adding that Scala 2:

$ scalac -d /tmp/sandbox -Xlint i20536.scala
i20536.scala:3: warning: type parameter Int defined in trait ImportUnusedSpecializedRename shadows class Int defined in package scala. You may want to rename your type parameter, or possibly remove it.
trait ImportUnusedSpecializedRename[@sp Int]
                                        ^
1 warning

Scala 3

$ scalac -d /tmp/sandbox -Wshadow:all i20536.scala
-- Warning: i20536.scala:3:40 ------------------------------------------------------------------------------------------
3 |trait ImportUnusedSpecializedRename[@sp Int]
  |                                    ^^^^^^^
  | Type parameter Int for trait ImportUnusedSpecializedRename shadows the type defined by class Int in package scala
1 warning found

@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 Jun 11, 2024
@satorg
Copy link
Author

satorg commented Jun 11, 2024

Ah, sorry, I overworked it a little. In Cats it is a generic A, not Int:
https://github.com/typelevel/cats/blob/90db3cd0269cf2b621ad6460ded594aee2e6a135/kernel/src/main/scala/cats/kernel/Enumerable.scala#L25-L34

@som-snytt
Copy link
Contributor

I didn't intend to rub it in. My point was going to be that scala 2 will lint that, but then I looked and scala 3 does it now too. I'll have to find some other clever thing to point out.

@WojciechMazur WojciechMazur added this to the 3.6.0 milestone Oct 8, 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

Successfully merging a pull request may close this issue.

3 participants