From 785f4fe224302bbddbbd6a198f1722b4c0ae17f7 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Tue, 20 Dec 2016 14:35:43 -0800 Subject: SI-8040 Xlint enables unused warnings `-Ywarn-unused-import` is deprecated in favor of `-Ywarn-unused:imports`. `-Xlint` does not yet enable `-Ywarn-unused:patvars`. But the default for `-Ywarn-unused` is everything, including `patvars`. So `-Xlint:unused` is the populist option, `-Ywarn-unused` more exclusive. Tests are fixed by narrowing scope of `-Xlint` when specified. --- src/compiler/scala/tools/nsc/settings/Warnings.scala | 10 ++++------ test/files/neg/abstract-inaccessible.check | 2 +- test/files/neg/abstract-inaccessible.flags | 2 +- test/files/neg/abstract-inaccessible.scala | 2 +- test/files/neg/forgot-interpolator.flags | 2 +- test/files/neg/overloaded-implicit.flags | 2 +- test/files/neg/t1980.flags | 2 +- test/files/neg/t4877.flags | 1 - test/files/neg/t6567.flags | 2 +- test/files/neg/t6675.flags | 2 +- test/files/neg/warn-unused-imports.flags | 2 +- test/files/pos/t6091.scala | 4 ++-- test/files/pos/t8013.flags | 2 +- test/files/pos/t8040.flags | 1 + test/files/pos/t8040.scala | 6 ++++++ 15 files changed, 23 insertions(+), 19 deletions(-) delete mode 100644 test/files/neg/t4877.flags create mode 100644 test/files/pos/t8040.flags create mode 100644 test/files/pos/t8040.scala diff --git a/src/compiler/scala/tools/nsc/settings/Warnings.scala b/src/compiler/scala/tools/nsc/settings/Warnings.scala index 29138c78d1..eb78064155 100644 --- a/src/compiler/scala/tools/nsc/settings/Warnings.scala +++ b/src/compiler/scala/tools/nsc/settings/Warnings.scala @@ -48,7 +48,7 @@ trait Warnings { BooleanSetting("-Ywarn-unused-import", "Warn when imports are unused.") withPostSetHook { s => warnUnused.add(s"${if (s) "" else "-"}imports") - } // withDeprecationMessage s"Enable -Ywarn-unused:imports" + } withDeprecationMessage s"Enable -Ywarn-unused:imports" val warnExtraImplicit = BooleanSetting("-Ywarn-extra-implicit", "Warn when more than one implicit parameter section is defined.") @@ -85,8 +85,7 @@ trait Warnings { val UnsoundMatch = LintWarning("unsound-match", "Pattern match may not be typesafe.") val StarsAlign = LintWarning("stars-align", "Pattern sequence wildcard must align with sequence component.") val Constant = LintWarning("constant", "Evaluation of a constant arithmetic expression results in an error.") - //val Unused = LintWarning("unused", "Warn when private and local definitions are unused.") - val Unused = LintWarning("unused", "Use -Ywarn-unused to warn when private and local definitions are unused.") + val Unused = LintWarning("unused", "Enable -Ywarn-unused:-patvars,_.") def allLintWarnings = values.toSeq.asInstanceOf[Seq[LintWarning]] } @@ -129,9 +128,8 @@ trait Warnings { helpArg = "warning", descr = "Enable or disable specific warnings", domain = LintWarnings, - default = Some(List("_"))) //.withPostSetHook (s => if (s contains Unused) warnUnused.add("_")) - - // restore -Xlint:unused hook when SI-8040 is complete + default = Some(List("_")) + ).withPostSetHook { s => if (s contains Unused) List("-patvars","_").foreach(warnUnused.add) } allLintWarnings foreach { case w if w.yAliased => diff --git a/test/files/neg/abstract-inaccessible.check b/test/files/neg/abstract-inaccessible.check index d56f5691be..739620a4ce 100644 --- a/test/files/neg/abstract-inaccessible.check +++ b/test/files/neg/abstract-inaccessible.check @@ -8,7 +8,7 @@ Classes which cannot access Bippy may be unable to override overrideMe. ^ abstract-inaccessible.scala:7: warning: method overrideMeAlso in trait YourTrait references private[foo] trait Bippy. Classes which cannot access Bippy may be unable to override overrideMeAlso. - def overrideMeAlso(x: Map[Int, Set[Bippy]]) = 5 + def overrideMeAlso(x: Map[Int, Set[Bippy]]) = x.keys.head ^ error: No warnings can be incurred under -Xfatal-warnings. three warnings found diff --git a/test/files/neg/abstract-inaccessible.flags b/test/files/neg/abstract-inaccessible.flags index 6c1dd108ae..ea7773e255 100644 --- a/test/files/neg/abstract-inaccessible.flags +++ b/test/files/neg/abstract-inaccessible.flags @@ -1 +1 @@ --Xfatal-warnings -Xlint \ No newline at end of file +-Xfatal-warnings -Xlint:inaccessible diff --git a/test/files/neg/abstract-inaccessible.scala b/test/files/neg/abstract-inaccessible.scala index 3c80f30522..02b458016f 100644 --- a/test/files/neg/abstract-inaccessible.scala +++ b/test/files/neg/abstract-inaccessible.scala @@ -4,6 +4,6 @@ package foo { trait YourTrait { def implementMe(f: Int => (String, Bippy)): Unit def overrideMe[T <: Bippy](x: T): T = x - def overrideMeAlso(x: Map[Int, Set[Bippy]]) = 5 + def overrideMeAlso(x: Map[Int, Set[Bippy]]) = x.keys.head } } diff --git a/test/files/neg/forgot-interpolator.flags b/test/files/neg/forgot-interpolator.flags index 7949c2afa2..b0d7bc25cb 100644 --- a/test/files/neg/forgot-interpolator.flags +++ b/test/files/neg/forgot-interpolator.flags @@ -1 +1 @@ --Xlint -Xfatal-warnings +-Xlint:missing-interpolator -Xfatal-warnings diff --git a/test/files/neg/overloaded-implicit.flags b/test/files/neg/overloaded-implicit.flags index 9c1e74e4ef..e04a4228ba 100644 --- a/test/files/neg/overloaded-implicit.flags +++ b/test/files/neg/overloaded-implicit.flags @@ -1 +1 @@ --Xlint -Xfatal-warnings -Xdev +-Xlint:poly-implicit-overload -Xfatal-warnings -Xdev diff --git a/test/files/neg/t1980.flags b/test/files/neg/t1980.flags index 7949c2afa2..cdc464a47d 100644 --- a/test/files/neg/t1980.flags +++ b/test/files/neg/t1980.flags @@ -1 +1 @@ --Xlint -Xfatal-warnings +-Xlint:by-name-right-associative -Xfatal-warnings diff --git a/test/files/neg/t4877.flags b/test/files/neg/t4877.flags deleted file mode 100644 index 7ccd56103a..0000000000 --- a/test/files/neg/t4877.flags +++ /dev/null @@ -1 +0,0 @@ --Xlint \ No newline at end of file diff --git a/test/files/neg/t6567.flags b/test/files/neg/t6567.flags index e93641e931..076333a011 100644 --- a/test/files/neg/t6567.flags +++ b/test/files/neg/t6567.flags @@ -1 +1 @@ --Xlint -Xfatal-warnings \ No newline at end of file +-Xlint:option-implicit -Xfatal-warnings diff --git a/test/files/neg/t6675.flags b/test/files/neg/t6675.flags index 2843ea9efc..c6bfaf1f64 100644 --- a/test/files/neg/t6675.flags +++ b/test/files/neg/t6675.flags @@ -1 +1 @@ --deprecation -Xlint -Xfatal-warnings \ No newline at end of file +-deprecation -Xfatal-warnings diff --git a/test/files/neg/warn-unused-imports.flags b/test/files/neg/warn-unused-imports.flags index 24db705df1..c4e11e7fe7 100644 --- a/test/files/neg/warn-unused-imports.flags +++ b/test/files/neg/warn-unused-imports.flags @@ -1 +1 @@ --Xfatal-warnings -Ywarn-unused-import +-Xfatal-warnings -Ywarn-unused:imports diff --git a/test/files/pos/t6091.scala b/test/files/pos/t6091.scala index 72e663ec3b..0318640e7b 100644 --- a/test/files/pos/t6091.scala +++ b/test/files/pos/t6091.scala @@ -1,6 +1,6 @@ -object Foo { def eq(x:Int) = x } +object Foo { def eq(x: Int) = x } -class X { def ==(other: String) = true } +class X { def ==(other: String) = other.nonEmpty } object Test { def main(args: Array[String]): Unit = { diff --git a/test/files/pos/t8013.flags b/test/files/pos/t8013.flags index 3955bb6710..219723cec9 100644 --- a/test/files/pos/t8013.flags +++ b/test/files/pos/t8013.flags @@ -1 +1 @@ --Xfatal-warnings -Xlint:-infer-any,_ +-Xfatal-warnings -Xlint:missing-interpolator diff --git a/test/files/pos/t8040.flags b/test/files/pos/t8040.flags new file mode 100644 index 0000000000..3126c059f0 --- /dev/null +++ b/test/files/pos/t8040.flags @@ -0,0 +1 @@ +-Xfatal-warnings -Ywarn-unused:params diff --git a/test/files/pos/t8040.scala b/test/files/pos/t8040.scala new file mode 100644 index 0000000000..b067f36b0b --- /dev/null +++ b/test/files/pos/t8040.scala @@ -0,0 +1,6 @@ + +object Test { + implicit class C(val sc: StringContext) { // no warn unused sc + def c(args: Any*): String = "c?" + args.mkString(",") // would warn unused args + } +} -- cgit v1.2.3