@@ -17,12 +17,15 @@ trait Warnings {
1717 // Warning semantics.
1818 val fatalWarnings = BooleanSetting (" -Xfatal-warnings" , " Fail the compilation if there are any warnings." )
1919
20- // These warnings are all so noisy as to be useless in their
20+ // These additional warnings are all so noisy as to be useless in their
2121 // present form, but have the potential to offer useful info.
2222 protected def allWarnings = lintWarnings ++ List (
2323 warnDeadCode,
2424 warnValueDiscard,
25- warnNumericWiden
25+ warnNumericWiden,
26+ warnUnused, // SI-7712, SI-7707 warnUnused not quite ready for prime-time
27+ warnUnusedImport, // currently considered too noisy for general use
28+ warnValueOverrides // currently turned off as experimental
2629 )
2730 // These warnings should be pretty quiet unless you're doing
2831 // something inadvisable.
@@ -32,9 +35,6 @@ trait Warnings {
3235 warnNullaryUnit,
3336 warnAdaptedArgs,
3437 warnInferAny,
35- // warnUnused SI-7712, SI-7707 warnUnused not quite ready for prime-time
36- // warnUnusedImport currently considered too noisy for general use
37- // warnValueOverrides
3838 warnMissingInterpolator,
3939 warnDocDetached,
4040 warnPrivateShadow,
@@ -46,22 +46,26 @@ trait Warnings {
4646 warnUnsoundMatch
4747 )
4848
49- private lazy val warnSelectNullable = BooleanSetting (" -Xcheck-null" , " This option is obsolete and does nothing." )
49+ // Individual warnings. They can be set with -Ywarn.
50+ private def nonlintflag (name : String , text : String ): BooleanSetting = BooleanSetting (name, text)
5051
51- // Individual warnings.
52- val warnDeadCode = BooleanSetting (" -Ywarn-dead-code" ,
52+ val warnDeadCode = nonlintflag(" -Ywarn-dead-code" ,
5353 " Warn when dead code is identified." )
54- val warnValueDiscard = BooleanSetting (" -Ywarn-value-discard" ,
54+ val warnValueDiscard = nonlintflag (" -Ywarn-value-discard" ,
5555 " Warn when non-Unit expression results are unused." )
56- val warnNumericWiden = BooleanSetting (" -Ywarn-numeric-widen" ,
56+ val warnNumericWiden = nonlintflag (" -Ywarn-numeric-widen" ,
5757 " Warn when numerics are widened." )
58- val warnUnused = BooleanSetting (" -Ywarn-unused" ,
58+ val warnUnused = nonlintflag (" -Ywarn-unused" ,
5959 " Warn when local and private vals, vars, defs, and types are are unused" )
60- val warnUnusedImport = BooleanSetting (" -Ywarn-unused-import" ,
60+ val warnUnusedImport = nonlintflag (" -Ywarn-unused-import" ,
6161 " Warn when imports are unused" )
6262
63- // Lint warnings that are not -Y, created with new instead of autoregistering factory method
64- private def lintflag (name : String , text : String ) = new BooleanSetting (name, text)
63+ // Lint warnings that have no -Y avatar, created with new instead of the autoregistering factory method.
64+ // They evaluate true if set to true or else are unset but -Xlint is true
65+ private def lintflag (name : String , text : String ): BooleanSetting =
66+ new BooleanSetting (name, text) {
67+ override def value = if (isSetByUser) super .value else xlint
68+ }
6569
6670 val warnAdaptedArgs = lintflag(" adapted-args" ,
6771 " Warn if an argument list is modified to match the receiver." )
@@ -92,59 +96,65 @@ trait Warnings {
9296 val warnUnsoundMatch = lintflag(" unsound-match" ,
9397 " Pattern match may not be typesafe" )
9498
95- // Lint warnings that are not enabled yet
96- val warnValueOverrides = lintflag(" value-overrides" , " Generated value class method overrides an implementation" )
99+ // Experimental lint warnings that are turned off, but which could be turned on programmatically.
100+ // These warnings are said to blind those who dare enable them.
101+ // They are not activated by -Xlint and can't be enabled on the command line.
102+ val warnValueOverrides = {
103+ val flag = lintflag(" value-overrides" , " Generated value class method overrides an implementation" )
104+ flag.value = false
105+ flag
106+ }
97107
98- // Warning groups.
99- val lint = {
100- // Boolean setting for testing if lint is on; not "added" to option processing
101- val xlint = lintflag(" -Xlint" , " Enable recommended additional warnings." )
102- val yprefix = " -Ywarn-"
103- def lintables = (lintWarnings map (_.name stripPrefix yprefix)).sorted
104- def isAnon (b : BooleanSetting ) = ! (b.name startsWith " -" )
105- def setPolitely (b : BooleanSetting , v : Boolean ) = if (! b.isSetByUser) b.value = v
106- def set (w : String , v : Boolean ) = lintWarnings find (s => (s.name stripPrefix yprefix) == w) foreach (b => setPolitely(b, v))
107- val Neg = " -"
108- def propagate (ss : List [String ]): Unit = ss match {
109- case w :: rest => if (w startsWith Neg ) set(w stripPrefix Neg , false ) else set(w, true ) ; propagate(rest)
110- case Nil => ()
111- }
112- // enable lint and the group, honoring previous -Y settings
113- def enableAll (): Unit = {
114- xlint.value = true
115- for (s <- lintWarnings) setPolitely(s, true )
108+ // The Xlint warning group.
109+ private val xlint = new BooleanSetting (" -Zunused" , " True if -Xlint or -Xlint:_" )
110+ // On -Xlint or -Xlint:_, set xlint, otherwise set the lint warning unless already set true
111+ val lint = {
112+ val description = " Enable or disable specific warnings"
113+ val choices = (lintWarnings map (_.name)).sorted
114+ MultiChoiceSetting (
115+ name = " -Xlint" ,
116+ helpArg = " warning" ,
117+ descr = description,
118+ choices = choices,
119+ default = () => xlint.value = true
120+ ) { s =>
121+ def helpline (n : String ) = lintWarnings.find(_.name == n).map(w => f " ${w.name}%-25s ${w.helpDescription}%n " )
122+ choices flatMap (helpline(_)) mkString (f " $description:%n " , " " , f " %n " )
123+ } withPostSetHook { x =>
124+ val Neg = " -"
125+ def setPolitely (b : BooleanSetting , v : Boolean ) = if (! b.isSetByUser || ! b) b.value = v
126+ def set (w : String , v : Boolean ) = lintWarnings find (_.name == w) foreach (setPolitely(_, v))
127+ def propagate (ss : List [String ]): Unit = ss match {
128+ case w :: rest => if (w startsWith Neg ) set(w stripPrefix Neg , false ) else set(w, true ) ; propagate(rest)
129+ case Nil => ()
130+ }
131+ propagate(x.value)
116132 }
117- // The command option
118- MultiChoiceSetting (" -Xlint" , " warning" , " Enable recommended additional warnings" , choices = lintables, default = enableAll) withPostSetHook { x =>
119- propagate(x.value) // enabling the selections (on each append to value)
120- xlint.value = true // only enables lint, not the group
121- for (b <- lintWarnings if isAnon(b) && ! b.isSetByUser) b.value = true // init anonymous settings (but not if disabled)
122- }
123- xlint
124133 }
125134
126135 // Lint warnings that are currently -Y, but deprecated in that usage
127- // Alas, the -Yarg must have a doppelgaenger that is not deprecated
128- @ deprecated(" Use the Xlint flag" , since= " 2.11.2" )
136+ @ deprecated(" Use warnAdaptedArgs" , since= " 2.11.2" )
129137 val YwarnAdaptedArgs = BooleanSetting (" -Ywarn-adapted-args" ,
130- " Warn if an argument list is modified to match the receiver." ) withDeprecationMessage
131- " Enable -Xlint:adapted-args" enabling List (warnAdaptedArgs)
132- @ deprecated(" Use the Xlint flag " , since= " 2.11.2" )
138+ " Warn if an argument list is modified to match the receiver." ) enabling List (warnAdaptedArgs)
139+ // withDeprecationMessage "Enable -Xlint:adapted-args"
140+ @ deprecated(" Use warnNullaryUnit " , since= " 2.11.2" )
133141 val YwarnNullaryUnit = BooleanSetting (" -Ywarn-nullary-unit" ,
134- " Warn when nullary methods return Unit." ) withDeprecationMessage
135- " Enable -Xlint:nullary-unit" enabling List (warnNullaryUnit)
136- @ deprecated(" Use the Xlint flag " , since= " 2.11.2" )
142+ " Warn when nullary methods return Unit." ) enabling List (warnNullaryUnit)
143+ // withDeprecationMessage "Enable -Xlint:nullary-unit"
144+ @ deprecated(" Use warnInaccessible " , since= " 2.11.2" )
137145 val YwarnInaccessible = BooleanSetting (" -Ywarn-inaccessible" ,
138- " Warn about inaccessible types in method signatures." ) withDeprecationMessage
139- " Enable -Xlint:inaccessible" enabling List (warnInaccessible)
140- @ deprecated(" Use the Xlint flag " , since= " 2.11.2" )
146+ " Warn about inaccessible types in method signatures." ) enabling List (warnInaccessible)
147+ // withDeprecationMessage "Enable -Xlint:inaccessible"
148+ @ deprecated(" Use warnNullaryOverride " , since= " 2.11.2" )
141149 val YwarnNullaryOverride = BooleanSetting (" -Ywarn-nullary-override" ,
142- " Warn when non-nullary `def f()' overrides nullary `def f'." ) withDeprecationMessage
143- " Enable -Xlint:nullary-override" enabling List (warnNullaryOverride)
144- @ deprecated(" Use the Xlint flag " , since= " 2.11.2" )
150+ " Warn when non-nullary `def f()' overrides nullary `def f'." ) enabling List (warnNullaryOverride)
151+ // withDeprecationMessage "Enable -Xlint:nullary-override"
152+ @ deprecated(" Use warnInferAny " , since= " 2.11.2" )
145153 val YwarnInferAny = BooleanSetting (" -Ywarn-infer-any" ,
146- " Warn when a type argument is inferred to be `Any`." ) withDeprecationMessage
147- " Enable -Xlint:infer-any" enabling List (warnInferAny)
154+ " Warn when a type argument is inferred to be `Any`." ) enabling List (warnInferAny)
155+ // withDeprecationMessage "Enable -Xlint:infer-any"
156+
157+ private lazy val warnSelectNullable = BooleanSetting (" -Xcheck-null" , " This option is obsolete and does nothing." )
148158
149159 // Backward compatibility.
150160 @ deprecated(" Use fatalWarnings" , " 2.11.0" ) def Xwarnfatal = fatalWarnings // used by sbt
0 commit comments