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:all causes a compilation error #16650

Closed
tgodzik opened this issue Jan 10, 2023 · 1 comment · Fixed by #16667
Closed

-Wunused:all causes a compilation error #16650

tgodzik opened this issue Jan 10, 2023 · 1 comment · Fixed by #16667
Assignees
Labels
area:transform itype:bug prio:high regression This worked in a previous version but doesn't anymore
Milestone

Comments

@tgodzik
Copy link
Contributor

tgodzik commented Jan 10, 2023

Compiler version

Started probably with 3.3.0-RC1-bin-20230109-f56089b-NIGHTLY and related to #16157

Minimized code

I think it's more about the classpath than it is about a specific code.

//> 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!")

Output

In the example:

Error compiling project (Scala 3.3.0-RC1-bin-20230109-f56089b-NIGHTLY, JVM)
Error: Unexpected error when compiling project_217a6bd2b4: 'Toplevel definition <init> is defined in
  /home/tgodzik/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-compiler_3/3.3.0-RC1-bin-20230109-f56089b-NIGHTLY/scala3-compiler_3-3.3.0-RC1-bin-20230109-f56089b-NIGHTLY.jar(dotty/tools/dotc/util/LinearSet$package.class)
and also in
  /home/tgodzik/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-compiler_3/3.3.0-RC1-bin-20230109-f56089b-NIGHTLY/scala3-compiler_3-3.3.0-RC1-bin-20230109-f56089b-NIGHTLY.jar(dotty/tools/dotc/util/LinearMap$package.class)
One of these files should be removed from the classpath.'
Compilation failed

Expectation

Compilation passes and shows unused warnings for a and LineraSet

@tgodzik tgodzik added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 10, 2023
tgodzik added a commit to tgodzik/metals that referenced this issue Jan 10, 2023
Previously, this was ignored, but with a recent merge this started to actually be calculated, but unfortunately it fail for out specific scenario. Now, I disable -Wunused:all until scala/scala3#16650 is fixed.
@szymon-rd szymon-rd self-assigned this Jan 10, 2023
@szymon-rd szymon-rd added area:transform and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 10, 2023
@szymon-rd szymon-rd modified the milestone: 3.3.0-RC1 Jan 10, 2023
@szymon-rd szymon-rd added prio:blocker regression This worked in a previous version but doesn't anymore and removed prio:blocker labels Jan 10, 2023
tgodzik added a commit to scalameta/metals that referenced this issue Jan 10, 2023
Previously, this was ignored, but with a recent merge this started to actually be calculated, but unfortunately it fail for out specific scenario. Now, I disable -Wunused:all until scala/scala3#16650 is fixed.
@SethTisue
Copy link
Member

SethTisue commented Jan 11, 2023

Dale found Martin's writeup at #7650 which is useful background. (And toplevel definitions are in play because that's what opaque types desugar to, in part. LinearSeq and LinearMap are opaque types in the same package but different source files.)

tgodzik added a commit to scalameta/metals that referenced this issue Jan 12, 2023
Previously, this was ignored, but with a recent merge this started to actually be calculated, but unfortunately it fail for out specific scenario. Now, I disable -Wunused:all until scala/scala3#16650 is fixed.
szymon-rd added a commit that referenced this issue Jan 12, 2023
… owner (also fix false positive for enum) (#16661)

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 "<init>" (constructor), so `member` fail to
resolve the name

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

:warning: 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):
```scala
//> 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!")
```
```bash
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)
@Kordyjan Kordyjan modified the milestones: 3.3.0-RC1, 3.3.0 Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:transform itype:bug prio:high regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants