diff options
author | Paul Phillips <paulp@improving.org> | 2012-10-30 14:29:14 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-11-01 18:50:43 -0700 |
commit | d0c4be6861109683d80513eda74e5c6ca88f1441 (patch) | |
tree | f0604d9f71cd0807e6a5a6351535a78ac18ddefc /test | |
parent | a70c8219220b637072b52fc834439d90f0cf5b38 (diff) | |
download | scala-d0c4be6861109683d80513eda74e5c6ca88f1441.tar.gz scala-d0c4be6861109683d80513eda74e5c6ca88f1441.tar.bz2 scala-d0c4be6861109683d80513eda74e5c6ca88f1441.zip |
Warn about unused private members.
Warnings enabled via -Xlint. It's one of the most requested
features. And it is hard to argue we don't need it: see the
99 methods removed in the next commit.
This should close SI-440.
Diffstat (limited to 'test')
-rw-r--r-- | test/files/neg/warn-unused-privates.check | 30 | ||||
-rw-r--r-- | test/files/neg/warn-unused-privates.flags | 1 | ||||
-rw-r--r-- | test/files/neg/warn-unused-privates.scala | 58 | ||||
-rw-r--r-- | test/files/pos/t5809.scala | 3 |
4 files changed, 91 insertions, 1 deletions
diff --git a/test/files/neg/warn-unused-privates.check b/test/files/neg/warn-unused-privates.check new file mode 100644 index 0000000000..c37e01106c --- /dev/null +++ b/test/files/neg/warn-unused-privates.check @@ -0,0 +1,30 @@ +warn-unused-privates.scala:2: warning: private constructor in class Bippy is never used + private def this(c: Int) = this(c, c) // warn + ^ +warn-unused-privates.scala:4: warning: private method in class Bippy is never used + private def boop(x: Int) = x+a+b // warn + ^ +warn-unused-privates.scala:6: warning: private getter in class Bippy is never used + final private val MILLIS2: Int = 1000 // warn + ^ +warn-unused-privates.scala:13: warning: private getter in object Bippy is never used + private val HEY_INSTANCE: Int = 1000 // warn + ^ +warn-unused-privates.scala:41: warning: private getter in trait Accessors is never used + private var v1: Int = 0 // warn + ^ +warn-unused-privates.scala:42: warning: private setter in trait Accessors is never used + private var v2: Int = 0 // warn, never set + ^ +warn-unused-privates.scala:43: warning: private getter in trait Accessors is never used + private var v3: Int = 0 // warn, never got + ^ +warn-unused-privates.scala:55: warning: private default argument in trait DefaultArgs is never used + private def bippy(x1: Int, x2: Int = 10, x3: Int = 15): Int = x1 + x2 + x3 + ^ +warn-unused-privates.scala:55: warning: private default argument in trait DefaultArgs is never used + private def bippy(x1: Int, x2: Int = 10, x3: Int = 15): Int = x1 + x2 + x3 + ^ +error: No warnings can be incurred under -Xfatal-warnings. +9 warnings found +one error found diff --git a/test/files/neg/warn-unused-privates.flags b/test/files/neg/warn-unused-privates.flags new file mode 100644 index 0000000000..7949c2afa2 --- /dev/null +++ b/test/files/neg/warn-unused-privates.flags @@ -0,0 +1 @@ +-Xlint -Xfatal-warnings diff --git a/test/files/neg/warn-unused-privates.scala b/test/files/neg/warn-unused-privates.scala new file mode 100644 index 0000000000..1ac272357f --- /dev/null +++ b/test/files/neg/warn-unused-privates.scala @@ -0,0 +1,58 @@ +class Bippy(a: Int, b: Int) { + private def this(c: Int) = this(c, c) // warn + private def bippy(x: Int): Int = bippy(x) // TODO: could warn + private def boop(x: Int) = x+a+b // warn + final private val MILLIS1 = 2000 // no warn, might have been inlined + final private val MILLIS2: Int = 1000 // warn + final private val HI_COMPANION: Int = 500 // no warn, accessed from companion + def hi() = Bippy.HI_INSTANCE +} +object Bippy { + def hi(x: Bippy) = x.HI_COMPANION + private val HI_INSTANCE: Int = 500 // no warn, accessed from instance + private val HEY_INSTANCE: Int = 1000 // warn +} + +class A(val msg: String) +class B1(msg: String) extends A(msg) +class B2(msg0: String) extends A(msg0) +class B3(msg0: String) extends A("msg") + +/*** Early defs full of noise due to SI-6595. ***/ +/*** +class Boppy extends { + private val hmm: String = "abc" // no warn, used in early defs + private val hom: String = "def" // no warn, used in body + private final val him = "ghi" // no warn, might have been (was) inlined + final val him2 = "ghi" // no warn, same + final val himinline = him + private val hum: String = "jkl" // warn + final val ding = hmm.length +} with Mutable { + val dinger = hom + private val hummer = "def" // warn + + private final val bum = "ghi" // no warn, might have been (was) inlined + final val bum2 = "ghi" // no warn, same +} +***/ + +trait Accessors { + private var v1: Int = 0 // warn + private var v2: Int = 0 // warn, never set + private var v3: Int = 0 // warn, never got + private var v4: Int = 0 // no warn + + def bippy(): Int = { + v3 = 5 + v4 = 6 + v2 + v4 + } +} + +trait DefaultArgs { + // warn about default getters for x2 and x3 + private def bippy(x1: Int, x2: Int = 10, x3: Int = 15): Int = x1 + x2 + x3 + + def boppy() = bippy(5, 100, 200) +} diff --git a/test/files/pos/t5809.scala b/test/files/pos/t5809.scala index 133e13c4ed..4bcd743faa 100644 --- a/test/files/pos/t5809.scala +++ b/test/files/pos/t5809.scala @@ -1,5 +1,6 @@ package object foo { implicit class PimpedInt(foo: Int) { def bar = ??? + def bippy = foo } -}
\ No newline at end of file +} |