summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/settings/Warnings.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/scala/tools/nsc/settings/Warnings.scala')
-rw-r--r--src/compiler/scala/tools/nsc/settings/Warnings.scala120
1 files changed, 62 insertions, 58 deletions
diff --git a/src/compiler/scala/tools/nsc/settings/Warnings.scala b/src/compiler/scala/tools/nsc/settings/Warnings.scala
index 3ff2369f86..0b9ad80041 100644
--- a/src/compiler/scala/tools/nsc/settings/Warnings.scala
+++ b/src/compiler/scala/tools/nsc/settings/Warnings.scala
@@ -17,12 +17,15 @@ trait Warnings {
// Warning semantics.
val fatalWarnings = BooleanSetting("-Xfatal-warnings", "Fail the compilation if there are any warnings.")
- // These warnings are all so noisy as to be useless in their
+ // These additional warnings are all so noisy as to be useless in their
// present form, but have the potential to offer useful info.
protected def allWarnings = lintWarnings ++ List(
warnDeadCode,
warnValueDiscard,
- warnNumericWiden
+ warnNumericWiden,
+ warnUnused, // SI-7712, SI-7707 warnUnused not quite ready for prime-time
+ warnUnusedImport, // currently considered too noisy for general use
+ warnValueOverrides // currently turned off as experimental
)
// These warnings should be pretty quiet unless you're doing
// something inadvisable.
@@ -32,9 +35,6 @@ trait Warnings {
warnNullaryUnit,
warnAdaptedArgs,
warnInferAny,
- // warnUnused SI-7712, SI-7707 warnUnused not quite ready for prime-time
- // warnUnusedImport currently considered too noisy for general use
- // warnValueOverrides
warnMissingInterpolator,
warnDocDetached,
warnPrivateShadow,
@@ -46,22 +46,26 @@ trait Warnings {
warnUnsoundMatch
)
- private lazy val warnSelectNullable = BooleanSetting("-Xcheck-null", "This option is obsolete and does nothing.")
+ // Individual warnings. They can be set with -Ywarn.
+ private def nonlintflag(name: String, text: String): BooleanSetting = BooleanSetting(name, text)
- // Individual warnings.
- val warnDeadCode = BooleanSetting("-Ywarn-dead-code",
+ val warnDeadCode = nonlintflag("-Ywarn-dead-code",
"Warn when dead code is identified.")
- val warnValueDiscard = BooleanSetting("-Ywarn-value-discard",
+ val warnValueDiscard = nonlintflag("-Ywarn-value-discard",
"Warn when non-Unit expression results are unused.")
- val warnNumericWiden = BooleanSetting("-Ywarn-numeric-widen",
+ val warnNumericWiden = nonlintflag("-Ywarn-numeric-widen",
"Warn when numerics are widened.")
- val warnUnused = BooleanSetting("-Ywarn-unused",
+ val warnUnused = nonlintflag("-Ywarn-unused",
"Warn when local and private vals, vars, defs, and types are are unused")
- val warnUnusedImport = BooleanSetting("-Ywarn-unused-import",
+ val warnUnusedImport = nonlintflag("-Ywarn-unused-import",
"Warn when imports are unused")
- // Lint warnings that are not -Y, created with new instead of autoregistering factory method
- private def lintflag(name: String, text: String) = new BooleanSetting(name, text)
+ // Lint warnings that have no -Y avatar, created with new instead of the autoregistering factory method.
+ // They evaluate true if set to true or else are unset but -Xlint is true
+ private def lintflag(name: String, text: String): BooleanSetting =
+ new BooleanSetting(name, text) {
+ override def value = if (isSetByUser) super.value else xlint
+ }
val warnAdaptedArgs = lintflag("adapted-args",
"Warn if an argument list is modified to match the receiver.")
@@ -92,59 +96,59 @@ trait Warnings {
val warnUnsoundMatch = lintflag("unsound-match",
"Pattern match may not be typesafe")
- // Lint warnings that are not enabled yet
- val warnValueOverrides = lintflag("value-overrides", "Generated value class method overrides an implementation")
+ // Experimental lint warnings that are turned off, but which could be turned on programmatically.
+ // These warnings are said to blind those who dare enable them.
+ // They are not activated by -Xlint and can't be enabled on the command line.
+ val warnValueOverrides = {
+ val flag = lintflag("value-overrides", "Generated value class method overrides an implementation")
+ flag.value = false
+ flag
+ }
- // Warning groups.
- val lint = {
- // Boolean setting for testing if lint is on; not "added" to option processing
- val xlint = lintflag("-Xlint", "Enable recommended additional warnings.")
- val yprefix = "-Ywarn-"
- def lintables = (lintWarnings map (_.name stripPrefix yprefix)).sorted
- def isAnon(b: BooleanSetting) = !(b.name startsWith "-")
- def setPolitely(b: BooleanSetting, v: Boolean) = if (!b.isSetByUser) b.value = v
- def set(w: String, v: Boolean) = lintWarnings find (s => (s.name stripPrefix yprefix) == w) foreach (b => setPolitely(b, v))
- val Neg = "-"
- def propagate(ss: List[String]): Unit = ss match {
- case w :: rest => if (w startsWith Neg) set(w stripPrefix Neg, false) else set(w, true) ; propagate(rest)
- case Nil => ()
- }
- // enable lint and the group, honoring previous -Y settings
- def enableAll(): Unit = {
- xlint.value = true
- for (s <- lintWarnings) setPolitely(s, true)
+ // The Xlint warning group.
+ private val xlint = new BooleanSetting("-Zunused", "True if -Xlint or -Xlint:_")
+ // On -Xlint or -Xlint:_, set xlint, otherwise set the lint warning unless already set true
+ val lint =
+ MultiChoiceSetting(
+ name = "-Xlint",
+ helpArg = "warning",
+ descr = "Enable recommended additional warnings",
+ choices = (lintWarnings map (_.name)).sorted,
+ default = () => xlint.value = true
+ ) withPostSetHook { x =>
+ val Neg = "-"
+ def setPolitely(b: BooleanSetting, v: Boolean) = if (!b.isSetByUser || !b) b.value = v
+ def set(w: String, v: Boolean) = lintWarnings find (_.name == w) foreach (setPolitely(_, v))
+ def propagate(ss: List[String]): Unit = ss match {
+ case w :: rest => if (w startsWith Neg) set(w stripPrefix Neg, false) else set(w, true) ; propagate(rest)
+ case Nil => ()
+ }
+ propagate(x.value)
}
- // The command option
- MultiChoiceSetting("-Xlint", "warning", "Enable recommended additional warnings", choices = lintables, default = enableAll) withPostSetHook { x =>
- propagate(x.value) // enabling the selections (on each append to value)
- xlint.value = true // only enables lint, not the group
- for (b <- lintWarnings if isAnon(b) && !b.isSetByUser) b.value = true // init anonymous settings (but not if disabled)
- }
- xlint
- }
// Lint warnings that are currently -Y, but deprecated in that usage
- // Alas, the -Yarg must have a doppelgaenger that is not deprecated
- @deprecated("Use the Xlint flag", since="2.11.2")
+ @deprecated("Use warnAdaptedArgs", since="2.11.2")
val YwarnAdaptedArgs = BooleanSetting("-Ywarn-adapted-args",
- "Warn if an argument list is modified to match the receiver.") withDeprecationMessage
- "Enable -Xlint:adapted-args" enabling List(warnAdaptedArgs)
- @deprecated("Use the Xlint flag", since="2.11.2")
+ "Warn if an argument list is modified to match the receiver.") enabling List(warnAdaptedArgs)
+ //withDeprecationMessage "Enable -Xlint:adapted-args"
+ @deprecated("Use warnNullaryUnit", since="2.11.2")
val YwarnNullaryUnit = BooleanSetting("-Ywarn-nullary-unit",
- "Warn when nullary methods return Unit.") withDeprecationMessage
- "Enable -Xlint:nullary-unit" enabling List(warnNullaryUnit)
- @deprecated("Use the Xlint flag", since="2.11.2")
+ "Warn when nullary methods return Unit.") enabling List(warnNullaryUnit)
+ //withDeprecationMessage "Enable -Xlint:nullary-unit"
+ @deprecated("Use warnInaccessible", since="2.11.2")
val YwarnInaccessible = BooleanSetting("-Ywarn-inaccessible",
- "Warn about inaccessible types in method signatures.") withDeprecationMessage
- "Enable -Xlint:inaccessible" enabling List(warnInaccessible)
- @deprecated("Use the Xlint flag", since="2.11.2")
+ "Warn about inaccessible types in method signatures.") enabling List(warnInaccessible)
+ //withDeprecationMessage "Enable -Xlint:inaccessible"
+ @deprecated("Use warnNullaryOverride", since="2.11.2")
val YwarnNullaryOverride = BooleanSetting("-Ywarn-nullary-override",
- "Warn when non-nullary `def f()' overrides nullary `def f'.") withDeprecationMessage
- "Enable -Xlint:nullary-override" enabling List(warnNullaryOverride)
- @deprecated("Use the Xlint flag", since="2.11.2")
+ "Warn when non-nullary `def f()' overrides nullary `def f'.") enabling List(warnNullaryOverride)
+ //withDeprecationMessage "Enable -Xlint:nullary-override"
+ @deprecated("Use warnInferAny", since="2.11.2")
val YwarnInferAny = BooleanSetting("-Ywarn-infer-any",
- "Warn when a type argument is inferred to be `Any`.") withDeprecationMessage
- "Enable -Xlint:infer-any" enabling List(warnInferAny)
+ "Warn when a type argument is inferred to be `Any`.") enabling List(warnInferAny)
+ //withDeprecationMessage "Enable -Xlint:infer-any"
+
+ 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