diff options
author | Paul Phillips <paulp@improving.org> | 2011-06-29 16:59:10 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-06-29 16:59:10 +0000 |
commit | fdfdd09d51f5ad3ee30e525145001f02959e3899 (patch) | |
tree | d82571210dc11a000cc15d6b17bda35b58bdee78 /src/compiler/scala/tools/nsc/settings/Warnings.scala | |
parent | 72a095dcdc84a988c61835d8115fd2738caa5127 (diff) | |
download | scala-fdfdd09d51f5ad3ee30e525145001f02959e3899.tar.gz scala-fdfdd09d51f5ad3ee30e525145001f02959e3899.tar.bz2 scala-fdfdd09d51f5ad3ee30e525145001f02959e3899.zip |
Warning! Warning! Yes, that's what's in this co...
Warning! Warning! Yes, that's what's in this commit. Why are you
panicking?
Mostly new command line options:
-Xlint // basically, the ones which aren't noisy Ywarn-all
-Ywarn-dead-code Ywarn-inaccessible // try this one on the library:
-it makes some good points Ywarn-nullary-override Ywarn-nullary-unit
-Ywarn-numeric-widen Ywarn-value-discard
Some accumulated motivations:
The wontfix resolution of ticket #4506 indicates that "def foo" and "def
foo()" are always going to be treated differently in some situations
and the same in others without users having any way to fix it. Summary
expressed in latest comment with which I agree (and quite sadly, given
that I've done a lot of work to try to make them usable) is "avoid using
structural types like the plague." But the least we can do is warn if
you're using parentheses "wrong".
I think it would be better if the warning about "def foo()" overriding
"def foo" were an error instead. If we have to live with this...
trait Me { def f(): Int }
class A { def f: Int = 5 }
class C extends A with Me { }
// error: Int does not take parameters
def f(x: C) = x.f()
// compiles
def f(x: Me) = x.f()
// error: Int does not take parameters. Mmph, how can a method be
// legal with parameter "Foo" and illegal with parameter "Foo with
// Bar" ?
def f(x: Me with C) = x.f()
The warning about a method contains a reference to a type which is less
accessible than the method itself is obviously to those who recall it
a response to GenTraversable being private and appearing in flatMap's
signature during the 2.9.0 RCs. It avoids warning in the case where the
unnormalized type is inaccessible but the normalized version would be,
but it could use further refinement.
Diffstat (limited to 'src/compiler/scala/tools/nsc/settings/Warnings.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/settings/Warnings.scala | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/settings/Warnings.scala b/src/compiler/scala/tools/nsc/settings/Warnings.scala new file mode 100644 index 0000000000..6fbd9892c7 --- /dev/null +++ b/src/compiler/scala/tools/nsc/settings/Warnings.scala @@ -0,0 +1,57 @@ +/* NSC -- new Scala compiler + * Copyright 2005-2011 LAMP/EPFL + * @author Paul Phillips + */ + +package scala.tools +package nsc +package settings + +import annotation.elidable +import scala.tools.util.PathResolver.Defaults +import scala.collection.mutable.HashSet + +/** Settings influencing the printing of warnings. + */ +trait Warnings { + self: MutableSettings => + + // 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 + // present form, but have the potential to offer useful info. + protected def allWarnings = lintWarnings ++ List( + warnSelectNullable, + warnValueDiscard, + warnNumericWiden + ) + // These warnings should be pretty quiet unless you're doing + // something inadvisable. + protected def lintWarnings = List( + warnDeadCode, + warnInaccessible, + warnNullaryOverride, + warnNullaryUnit + ) + + // Warning groups. + val lint = ( + BooleanSetting("-Xlint", "Enable recommended additional warnings.") + withPostSetHook (_ => lintWarnings foreach (_.value = true)) + ) + val warnEverything = ( + BooleanSetting("-Ywarn-all", "Enable all -Y warnings.") + withPostSetHook (_ => lintWarnings foreach (_.value = true)) + ) + + // Individual warnings. + val warnSelectNullable = BooleanSetting ("-Xcheck-null", "Warn upon selection of nullable reference.") + val warnDeadCode = BooleanSetting ("-Ywarn-dead-code", "Warn when dead code is identified.") + val warnValueDiscard = BooleanSetting ("-Ywarn-value-discard", "Warn when non-Unit expression results are unused.") + val warnNumericWiden = BooleanSetting ("-Ywarn-numeric-widen", "Warn when numerics are widened.") + val warnNullaryUnit = BooleanSetting ("-Ywarn-nullary-unit", "Warn when nullary methods return Unit.") + val warnInaccessible = BooleanSetting ("-Ywarn-inaccessible", "Warn about inaccessible types in method signatures.") + val warnNullaryOverride = BooleanSetting ("-Ywarn-nullary-override", + "Warn when non-nullary overrides nullary, e.g. `def foo()` over `def foo`.") +} |