I just noticed a bug in my code where I created a new variable, but then failed to actually use it.
I assumed that scalac would have told me that my new variable was unused, but this didn't seem to be the case, and after a small amount of googling / man page, I couldn't find anything about enabling warnings.
What can I do to enable such warnings?
Unused variables are a waste of space in the source; a decent compiler won't create them in the object file. Unused parameters when the functions have to meet an externally imposed interface are a different problem; they can't be avoided as easily because to remove them would be to change the interface.
As of scalac 2.12, you can now use -Ywarn-unused:locals
. In case you didn't mean just local variables, there are other options too:
$ scalac -Ywarn-unused:help
Enable or disable specific `unused' warnings
imports Warn if an import selector is not referenced.
patvars Warn if a variable bound in a pattern is unused.
privates Warn if a private member is unused.
locals Warn if a local definition is unused.
explicits Warn if an explicit parameter is unused.
implicits Warn if an implicit parameter is unused.
params Enable -Ywarn-unused:explicits,implicits.
linted -Xlint:unused.
Default: All choices are enabled by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With