Skip to content

Commit

Permalink
Merge pull request #6632 from som-snytt/issue/old-Y
Browse files Browse the repository at this point in the history
Prune -Ywarn aliased lint flags
  • Loading branch information
lrytz committed May 28, 2018
2 parents 077868c + ad25805 commit 39a5f0c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 53 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ lazy val macroAnnot = project.in(file("test") / "macro-annot")
baseDirectory in Test := (baseDirectory in ThisBuild).value,

scalacOptions += "-Ymacro-annotations",
scalacOptions += "-Ywarn-unused-import",
scalacOptions += "-Ywarn-unused:imports",
scalacOptions += "-Xfatal-warnings"
)

Expand Down
6 changes: 4 additions & 2 deletions project/ScalaOptionParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ object ScalaOptionParser {
"-Yoverride-objects", "-Yoverride-vars", "-Ypatmat-debug", "-Yno-adapted-args", "-Ypos-debug", "-Ypresentation-debug",
"-Ypresentation-strict", "-Ypresentation-verbose", "-Yquasiquote-debug", "-Yrangepos", "-Yreify-copypaste", "-Yreify-debug", "-Yrepl-class-based",
"-Yrepl-sync", "-Yshow-member-pos", "-Yshow-symkinds", "-Yshow-symowners", "-Yshow-syms", "-Yshow-trees", "-Yshow-trees-compact", "-Yshow-trees-stringified", "-Ytyper-debug",
"-Ywarn-adapted-args", "-Ywarn-dead-code", "-Ywarn-inaccessible", "-Ywarn-infer-any", "-Ywarn-nullary-override", "-Ywarn-nullary-unit", "-Ywarn-numeric-widen", "-Ywarn-unused-import", "-Ywarn-value-discard",
"-Ywarn-dead-code", "-Ywarn-numeric-widen", "-Ywarn-value-discard", "-Ywarn-extra-implicit", "-Ywarn-self-implicit",
"-deprecation", "-explaintypes", "-feature", "-help", "-no-specialization", "-nobootcp", "-nowarn", "-optimise", "-print", "-unchecked", "-uniqid", "-usejavacp", "-usemanifestcp", "-verbose", "-version")
private def stringSettingNames = List("-Xgenerate-phase-graph", "-Xmain-class", "-Xpluginsdir", "-Xshow-class", "-Xshow-object", "-Xsource-reader", "-Ydump-classes", "-Ygen-asmp",
"-Ypresentation-log", "-Ypresentation-replay", "-Yrepl-outdir", "-d", "-dependencyfile", "-encoding", "-Xscript")
Expand All @@ -108,9 +108,11 @@ object ScalaOptionParser {
"-g" -> List("line", "none", "notailcails", "source", "vars"),
"-target" -> List("jvm-1.5", "jvm-1.6", "jvm-1.7", "jvm-1.8"))
private def multiChoiceSettingNames = Map[String, List[String]](
"-Xlint" -> List("adapted-args", "nullary-unit", "inaccessible", "nullary-override", "infer-any", "missing-interpolator", "doc-detached", "private-shadow", "type-parameter-shadow", "poly-implicit-overload", "option-implicit", "delayedinit-select", "by-name-right-associative", "package-object-classes", "unsound-match", "stars-align"),
"-Xlint" -> List("adapted-args", "nullary-unit", "inaccessible", "nullary-override", "infer-any", "missing-interpolator", "doc-detached", "private-shadow", "type-parameter-shadow", "poly-implicit-overload", "option-implicit", "delayedinit-select", "by-name-right-associative", "package-object-classes", "unsound-match", "stars-align", "constant", "unused"),
"-language" -> List("help", "_", "dynamics", "postfixOps", "reflectiveCalls", "implicitConversions", "higherKinds", "existentials", "experimental.macros"),
"-opt" -> List("l:none", "l:default", "l:method", "l:project", "l:classpath", "unreachable-code", "simplify-jumps", "empty-line-numbers", "empty-labels", "compact-locals", "nullness-tracking", "closure-elimination", "inline-project", "inline-global"),
"-Ywarn-unused" -> List("imports", "patvars", "privates", "locals", "explicits", "implicits", "params"),
"-Ywarn-macros" -> List("none", "before", "after", "both"),
"-Ystatistics" -> List("parser", "typer", "patmat", "erasure", "cleanup", "jvm")
)
private def scalaVersionSettings = List("-Xmigration", "-Xsource")
Expand Down
44 changes: 10 additions & 34 deletions src/compiler/scala/tools/nsc/settings/Warnings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ trait Warnings {
def warnUnusedExplicits = warnUnused contains UnusedWarnings.Explicits
def warnUnusedImplicits = warnUnused contains UnusedWarnings.Implicits

BooleanSetting("-Ywarn-unused-import", "Warn when imports are unused.") withPostSetHook { s =>
warnUnused.add(s"${if (s) "" else "-"}imports")
} //withDeprecationMessage s"Enable -Ywarn-unused:imports"

val warnExtraImplicit = BooleanSetting("-Ywarn-extra-implicit", "Warn when more than one implicit parameter section is defined.")

val warnSelfImplicit = BooleanSetting("-Ywarn-self-implicit", "Warn when an implicit resolves to an enclosing self-definition.")
Expand All @@ -82,14 +78,14 @@ trait Warnings {
// Lint warnings

object LintWarnings extends MultiChoiceEnumeration {
class LintWarning(name: String, help: String, val yAliased: Boolean) extends Choice(name, help)
def LintWarning(name: String, help: String, yAliased: Boolean = false) = new LintWarning(name, help, yAliased)

val AdaptedArgs = LintWarning("adapted-args", "Warn if an argument list is modified to match the receiver.", true)
val NullaryUnit = LintWarning("nullary-unit", "Warn when nullary methods return Unit.", true)
val Inaccessible = LintWarning("inaccessible", "Warn about inaccessible types in method signatures.", true)
val NullaryOverride = LintWarning("nullary-override", "Warn when non-nullary `def f()' overrides nullary `def f'.", true)
val InferAny = LintWarning("infer-any", "Warn when a type argument is inferred to be `Any`.", true)
class LintWarning(name: String, help: String) extends Choice(name, help)
def LintWarning(name: String, help: String) = new LintWarning(name, help)

val AdaptedArgs = LintWarning("adapted-args", "Warn if an argument list is modified to match the receiver.")
val NullaryUnit = LintWarning("nullary-unit", "Warn when nullary methods return Unit.")
val Inaccessible = LintWarning("inaccessible", "Warn about inaccessible types in method signatures.")
val NullaryOverride = LintWarning("nullary-override", "Warn when non-nullary `def f()' overrides nullary `def f'.")
val InferAny = LintWarning("infer-any", "Warn when a type argument is inferred to be `Any`.")
val MissingInterpolator = LintWarning("missing-interpolator", "A string literal appears to be missing an interpolator id.")
val DocDetached = LintWarning("doc-detached", "A Scaladoc comment appears to be detached from its element.")
val PrivateShadow = LintWarning("private-shadow", "A private field (or class parameter) shadows a superclass field.")
Expand Down Expand Up @@ -129,18 +125,6 @@ trait Warnings {
def lintUnused = lint contains Unused
def warnNonlocalReturn = lint contains NonlocalReturn

// Lint warnings that are currently -Y, but deprecated in that usage
@deprecated("Use warnAdaptedArgs", since="2.11.2")
def YwarnAdaptedArgs = warnAdaptedArgs
@deprecated("Use warnNullaryUnit", since="2.11.2")
def YwarnNullaryUnit = warnNullaryUnit
@deprecated("Use warnInaccessible", since="2.11.2")
def YwarnInaccessible = warnInaccessible
@deprecated("Use warnNullaryOverride", since="2.11.2")
def YwarnNullaryOverride = warnNullaryOverride
@deprecated("Use warnInferAny", since="2.11.2")
def YwarnInferAny = warnInferAny

// The Xlint warning group.
val lint = MultiChoiceSetting(
name = "-Xlint",
Expand All @@ -153,18 +137,10 @@ trait Warnings {
else warnUnused.disable(UnusedWarnings.Linted)
}

allLintWarnings foreach {
case w if w.yAliased =>
BooleanSetting(s"-Ywarn-${w.name}", {w.help}) withPostSetHook { s =>
lint.add(if (s) w.name else s"-${w.name}")
} // withDeprecationMessage s"Enable -Xlint:${c._1}"
case _ =>
}

private lazy val warnSelectNullable = BooleanSetting("-Xcheck-null", "This option is obsolete and does nothing.")

// Backward compatibility.
@deprecated("Use fatalWarnings", "2.11.0") def Xwarnfatal = fatalWarnings // used by sbt

private lazy val warnSelectNullable = BooleanSetting("-Xcheck-null", "This option is obsolete and does nothing.")
@deprecated("This option is being removed", "2.11.0") def Xchecknull = warnSelectNullable // used by ide
@deprecated("Use warnDeadCode", "2.11.0") def Ywarndeadcode = warnDeadCode // used by ide
}
2 changes: 1 addition & 1 deletion test/files/neg/t8417.flags
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-Xfatal-warnings -Ywarn-adapted-args
-Xfatal-warnings -Xlint:adapted-args
18 changes: 3 additions & 15 deletions test/junit/scala/tools/nsc/settings/SettingsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class SettingsTest {
b(s)
}
@Test def userSettingsHavePrecedenceOverLint(): Unit = {
assertTrue(check("-Xlint")(_.warnAdaptedArgs))
assertFalse(check("-Xlint", "-Ywarn-adapted-args:false")(_.warnAdaptedArgs))
assertFalse(check("-Ywarn-adapted-args:false", "-Xlint")(_.warnAdaptedArgs))
assertTrue(check("-Xlint")(_.warnUnusedImport))
assertFalse(check("-Xlint", "-Ywarn-unused:-imports")(_.warnUnusedImport))
assertFalse(check("-Ywarn-unused:-imports", "-Xlint")(_.warnUnusedImport))
}

@Test def anonymousLintersCanBeNamed(): Unit = {
Expand Down Expand Up @@ -95,18 +95,6 @@ class SettingsTest {
assertTrue(check("-Xlint:-adapted-args,_,adapted-args")(t(_, "adapted-args")))
}

@Test def xLintDeprecatedAlias(): Unit = {
assertTrue(check("-Ywarn-adapted-args")(_.warnAdaptedArgs))
assertTrue(check("-Xlint:_,-adapted-args", "-Ywarn-adapted-args")(_.warnAdaptedArgs))
assertTrue(check("-Xlint:-adapted-args", "-Ywarn-adapted-args")(_.warnAdaptedArgs))
assertTrue(check("-Ywarn-adapted-args", "-Xlint:-adapted-args,_")(_.warnAdaptedArgs))

assertFalse(check("-Ywarn-adapted-args:false")(_.warnAdaptedArgs))
assertFalse(check("-Ywarn-adapted-args:false", "-Xlint:_")(_.warnAdaptedArgs))
assertFalse(check("-Ywarn-adapted-args:false", "-Xlint:_,-adapted-args")(_.warnAdaptedArgs))
assertTrue(check("-Ywarn-adapted-args:false", "-Xlint:_,adapted-args")(_.warnAdaptedArgs))
}

@Test def expandingMultichoice(): Unit = {
val s = new MutableSettings(msg => throw new IllegalArgumentException(msg))
object mChoices extends s.MultiChoiceEnumeration {
Expand Down

0 comments on commit 39a5f0c

Please sign in to comment.