Closed scabug closed 13 years ago
Imported From: https://issues.scala-lang.org/browse/SI-3952?orig=1 Reporter: @sbocq
@paulp said: There's the small matter that the underscore isn't legal syntax. I do have a fairly complete private spotting plugin which I'll finish one of these days. Going to call this a duplicate of #441.
@sbocq said: Replying to [comment:1 extempore]:
There's the small matter that the underscore isn't legal syntax. I do have a fairly complete private spotting plugin which I'll finish one of these days. Going to call this a duplicate of #441.
Couldn't this syntax become legal? A plugin will do the job for unused vars but not for unused method parameters because there won't be a way to remove the warning condition.
@paulp said: Replying to [comment:2 sbocq]:
Couldn't this syntax become legal? A plugin will do the job for unused vars but not for unused method parameters because there won't be a way to remove the warning condition.
It could become legal, but then you've far exceeded ticket scope since you're proposing a language change and that requires a SID. You're quite right that half the reason I haven't finished that plugin is that I don't have a good way to deal with the noise generated when they are intentionally unused. It probably ends up as an annotation, which isn't too bad in a lintlike plugin - it's kind of what annotations were designed for.
@sbocq said: Sounds reasonable otherwise I'd write a SID but my lack of knowledge of the compiler internals does not permit it. I'll be looking forward your plugin, thanks for taking that up!
$ scala -Ywarn-unused
Welcome to Scala 2.12.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_144).
Type in expressions for evaluation. Or try :help.
scala> def f(x: Int) = 42
<console>:11: warning: parameter value x in method f is never used
def f(x: Int) = 42
^
f: (x: Int)Int
scala> def f(@deprecated x: Int) = 42
<console>:11: warning: @deprecated now takes two arguments; see the scaladoc.
def f(@deprecated x: Int) = 42
^
f: (x: Int)Int
scala> def f(@deprecated("","") x: Int) = 42
f: (x: Int)Int
It would be nice if the compiler could give a warning when method parameters are not used and suggest to use wildcard as parameter name instead.
For example, looking at this method:
def foo(a:Int, b:Int, c:Int):Int = a + b
one can hardly tell if it is a bug or not. Writing it like below would make the intent explicit:
def foo(a:Int, b:Int, _:Int):Int = a + b
Cheers!