|
| 1 | +//> using options -Wunused:params -Werror |
| 2 | +// |
| 3 | + |
| 4 | +import Answers._ |
| 5 | + |
| 6 | +trait InterFace { |
| 7 | + /** Call something. */ |
| 8 | + def call(a: Int, b: String, c: Double): Int |
| 9 | +} |
| 10 | + |
| 11 | +trait BadAPI extends InterFace { |
| 12 | + def f(a: Int, |
| 13 | + b: String, // warn |
| 14 | + c: Double): Int = { |
| 15 | + println(c) |
| 16 | + a |
| 17 | + } |
| 18 | + @deprecated("no warn in deprecated API", since="yesterday") |
| 19 | + def g(a: Int, |
| 20 | + b: String, // no warn |
| 21 | + c: Double): Int = { |
| 22 | + println(c) |
| 23 | + a |
| 24 | + } |
| 25 | + override def call(a: Int, |
| 26 | + b: String, // no warn, required by superclass |
| 27 | + c: Double): Int = { |
| 28 | + println(c) |
| 29 | + a |
| 30 | + } |
| 31 | + |
| 32 | + def meth(x: Int) = x |
| 33 | + |
| 34 | + override def equals(other: Any): Boolean = true // no warn |
| 35 | + |
| 36 | + def i(implicit s: String) = answer // yes, warn |
| 37 | + |
| 38 | + /* |
| 39 | + def future(x: Int): Int = { |
| 40 | + val y = 42 |
| 41 | + val x = y // maybe option to warn only if shadowed |
| 42 | + x |
| 43 | + } |
| 44 | + */ |
| 45 | +} |
| 46 | + |
| 47 | +// mustn't alter warnings in super |
| 48 | +trait PoorClient extends BadAPI { |
| 49 | + override def meth(x: Int) = ??? // no warn |
| 50 | + override def f(a: Int, b: String, c: Double): Int = a + b.toInt + c.toInt |
| 51 | +} |
| 52 | + |
| 53 | +class Unusing(u: Int) { // warn |
| 54 | + def f = ??? |
| 55 | +} |
| 56 | + |
| 57 | +class Valuing(val u: Int) // no warn |
| 58 | + |
| 59 | +class Revaluing(u: Int) { def f = u } // no warn |
| 60 | + |
| 61 | +case class CaseyKasem(k: Int) // no warn |
| 62 | + |
| 63 | +case class CaseyAtTheBat(k: Int)(s: String) // warn |
| 64 | + |
| 65 | +trait Ignorance { |
| 66 | + def f(readResolve: Int) = answer // warn |
| 67 | +} |
| 68 | + |
| 69 | +class Reusing(u: Int) extends Unusing(u) // no warn |
| 70 | + |
| 71 | +class Main { |
| 72 | + def main(args: Array[String]): Unit = println("hello, args") // no warn |
| 73 | +} |
| 74 | + |
| 75 | +trait Unimplementation { |
| 76 | + def f(u: Int): Int = ??? // no warn for param in unimplementation |
| 77 | +} |
| 78 | + |
| 79 | +trait DumbStuff { |
| 80 | + def f(implicit dummy: DummyImplicit) = answer |
| 81 | + def g(dummy: DummyImplicit) = answer |
| 82 | +} |
| 83 | +trait Proofs { |
| 84 | + def f[A, B](implicit ev: A =:= B) = answer |
| 85 | + def g[A, B](implicit ev: A <:< B) = answer |
| 86 | + def f2[A, B](ev: A =:= B) = answer |
| 87 | + def g2[A, B](ev: A <:< B) = answer |
| 88 | +} |
| 89 | + |
| 90 | +trait Anonymous { |
| 91 | + def f = (i: Int) => answer // warn |
| 92 | + |
| 93 | + def f1 = (_: Int) => answer // no warn underscore parameter (a fresh name) |
| 94 | + |
| 95 | + def f2: Int => Int = _ + 1 // no warn placeholder syntax (a fresh name and synthetic parameter) |
| 96 | + |
| 97 | + def g = for (i <- List(1)) yield answer // no warn patvar elaborated as map.(i => 42) |
| 98 | +} |
| 99 | +trait Context[A] { def m(a: A): A = a } |
| 100 | +trait Implicits { |
| 101 | + def f[A](implicit ctx: Context[A]) = answer |
| 102 | + def g[A: Context] = answer |
| 103 | +} |
| 104 | +class Bound[A: Context] |
| 105 | +object Answers { |
| 106 | + def answer: Int = 42 |
| 107 | +} |
| 108 | + |
| 109 | +trait BadMix { _: InterFace => |
| 110 | + def f(a: Int, |
| 111 | + b: String, // warn |
| 112 | + c: Double): Int = { |
| 113 | + println(c) |
| 114 | + a |
| 115 | + } |
| 116 | + @deprecated("no warn in deprecated API", since="yesterday") |
| 117 | + def g(a: Int, |
| 118 | + b: String, // no warn |
| 119 | + c: Double): Int = { |
| 120 | + println(c) |
| 121 | + a |
| 122 | + } |
| 123 | + override def call(a: Int, |
| 124 | + b: String, // no warn, required by superclass |
| 125 | + c: Double): Int = { |
| 126 | + println(c) |
| 127 | + a |
| 128 | + } |
| 129 | + |
| 130 | + def meth(x: Int) = x |
| 131 | + |
| 132 | + override def equals(other: Any): Boolean = true // no warn |
| 133 | + |
| 134 | + def i(implicit s: String) = answer // yes, warn |
| 135 | +} |
| 136 | + |
| 137 | +class Unequal { |
| 138 | + override def equals(other: Any) = toString.nonEmpty // no warn non-trivial RHS, required by universal method |
| 139 | +} |
| 140 | + |
| 141 | +class Seriously { |
| 142 | + def f(s: Serializable) = toString.nonEmpty // warn explicit param of marker trait |
| 143 | +} |
| 144 | + |
| 145 | +class TryStart(start: String) { |
| 146 | + def FINALLY(end: END.type) = start |
| 147 | +} |
| 148 | + |
| 149 | +object END |
| 150 | + |
| 151 | +class Nested { |
| 152 | + @annotation.unused private def actuallyNotUsed(fresh: Int, stale: Int) = fresh |
| 153 | +} |
0 commit comments