summaryrefslogtreecommitdiff
path: root/test/files/neg/warn-unused-privates.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-10-30 14:29:14 -0700
committerAdriaan Moors <adriaan.moors@epfl.ch>2012-11-01 18:50:43 -0700
commitd0c4be6861109683d80513eda74e5c6ca88f1441 (patch)
treef0604d9f71cd0807e6a5a6351535a78ac18ddefc /test/files/neg/warn-unused-privates.scala
parenta70c8219220b637072b52fc834439d90f0cf5b38 (diff)
downloadscala-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/files/neg/warn-unused-privates.scala')
-rw-r--r--test/files/neg/warn-unused-privates.scala58
1 files changed, 58 insertions, 0 deletions
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)
+}