bug
bug copied to clipboard
-Wunused:locals does not produce a warning for simple values
Reproduction steps
Scala version: 2.13.8
object Example extends App {
def unusedLocal = {
val a = 1
2
}
}
with the compiler option
"-Wunused:locals"
(and thus -Xlint:unused ...)
Problem
I would expect 'val a' to be reported as 'never used', but there is no warning.
If either line 3 is changed to e.g. val a = 1+1 OR line 4 changed to e.g. '2+1', there is a warning.
might be @som-snytt territory?
The trivial assignment is eliminated early, which amazes me. "There is no assignment. There is nothing to see here." That's an old Jedi mind trick.
So is there any realistic possibility of this progressing?
It's probably merely idle curiosity, but I'm curious what the transform is that causes it to be eliminated?
https://github.com/scala/scala/blob/3faf9a98282a2f06219fd0b05b7fede2ab8fb326/src/compiler/scala/tools/nsc/typechecker/Typers.scala#L6268
I was surprised to find val a: Int = 1; disappeared from here.
Probably just inlined.