Commit 483b1e8
authored
Fix -Wunused:import registering constructor ("<init>") instead of its 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)File tree
3 files changed
+25
-3
lines changed- compiler/src/dotty/tools/dotc/transform
- tests/neg-custom-args/fatal-warnings
3 files changed
+25
-3
lines changedLines changed: 10 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
326 | 327 | | |
327 | 328 | | |
328 | 329 | | |
329 | | - | |
330 | 330 | | |
331 | 331 | | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
332 | 336 | | |
333 | 337 | | |
334 | 338 | | |
| |||
345 | 349 | | |
346 | 350 | | |
347 | 351 | | |
348 | | - | |
| 352 | + | |
349 | 353 | | |
350 | 354 | | |
351 | 355 | | |
| |||
589 | 593 | | |
590 | 594 | | |
591 | 595 | | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
592 | 600 | | |
593 | 601 | | |
594 | 602 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
253 | | - | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
0 commit comments