diff options
author | Som Snytt <som.snytt@gmail.com> | 2016-09-19 00:46:17 -0700 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2017-03-11 23:38:08 -0800 |
commit | 22f98d5189b61200aaf11cec7a0a96d5cfa86a5e (patch) | |
tree | aa90424f6dd21609090ae8fbffb5410ca80f4edf /test/files/neg/warn-unused-params.scala | |
parent | 94b938bb290a231694e5721368023bd6693bb2ed (diff) | |
download | scala-22f98d5189b61200aaf11cec7a0a96d5cfa86a5e.tar.gz scala-22f98d5189b61200aaf11cec7a0a96d5cfa86a5e.tar.bz2 scala-22f98d5189b61200aaf11cec7a0a96d5cfa86a5e.zip |
SI-8040 Warn unused parameters
One can `-Ywarn-unused:params` or more narrowly warn only for
unused implicit parameters with `-Ywarn-unused:implicits`.
Params includes constructor parameters.
The settings for privates and locals are not yet distinguished.
```
$ skalac -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.
params Warn if a value parameter is unused.
implicits Warn if an implicit parameter is unused.
```
Diffstat (limited to 'test/files/neg/warn-unused-params.scala')
-rw-r--r-- | test/files/neg/warn-unused-params.scala | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test/files/neg/warn-unused-params.scala b/test/files/neg/warn-unused-params.scala new file mode 100644 index 0000000000..c7578e53a4 --- /dev/null +++ b/test/files/neg/warn-unused-params.scala @@ -0,0 +1,61 @@ + +trait InterFace { + /** Call something. */ + def call(a: Int, b: String, c: Double): Int +} + +trait BadAPI extends InterFace { + def f(a: Int, + b: String, // warn + c: Double): Int = { + println(c) + a + } + @deprecated ("no warn in deprecated API", since="yesterday") + def g(a: Int, + b: String, // no warn + c: Double): Int = { + println(c) + a + } + override def call(a: Int, + b: String, // no warn, required by superclass + c: Double): Int = { + println(c) + a + } + + def meth(x: Int) = x + + override def equals(other: Any): Boolean = true // no warn + + def i(implicit s: String) = 42 // yes, warn + + /* + def future(x: Int): Int = { + val y = 42 + val x = y // maybe option to warn only if shadowed + x + } + */ +} + +// mustn't alter warnings in super +trait PoorClient extends BadAPI { + override def meth(x: Int) = ??? // no warn + override def f(a: Int, b: String, c: Double): Int = a + b.toInt + c.toInt +} + +class Unusing(u: Int) { // warn + def f = ??? +} + +class Valuing(val u: Int) // no warn + +case class CaseyKasem(k: Int) // no warn + +case class CaseyAtTheBat(k: Int)(s: String) // warn + +trait Ignorance { + def f(readResolve: Int) = 42 // warn +} |