summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2016-09-15 23:16:40 -0700
committerSom Snytt <som.snytt@gmail.com>2017-03-11 23:38:08 -0800
commit94b938bb290a231694e5721368023bd6693bb2ed (patch)
treece8366bfa9b301add12d53f2ddf13fe7e05b235a /src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
parentbd280077d04a3ac84ca48f549faaa8915d46ef2e (diff)
downloadscala-94b938bb290a231694e5721368023bd6693bb2ed.tar.gz
scala-94b938bb290a231694e5721368023bd6693bb2ed.tar.bz2
scala-94b938bb290a231694e5721368023bd6693bb2ed.zip
SI-8040 Warn unused flags
Introduce `-Ywarn-unused:x,y,z` and exploit `-Ywarn-unused:patvars`. Although the tree attachment for shielding patvars from warnings is not structural, sneaking the settings flag into the reflection internal TreeGen is awkward. Add test to ensure isolation of patvars warning from others. `-Ywarn-unused-import` is an alias for `-Ywarn-unused:imports`. `-Xlint:unused` is an alias for `-Ywarn-unused`, but not enabled yet. The help text advises to use `-Ywarn-unused`. The future can decide if `-Xlint:unused-imports` is warranted.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
index f344364a75..b263a0fffd 100644
--- a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
@@ -505,7 +505,7 @@ trait TypeDiagnostics {
// Only record type references which don't originate within the
// definition of the class being referenced.
if (t.tpe ne null) {
- for (tp <- t.tpe ; if !treeTypes(tp) && !currentOwner.ownerChain.contains(tp.typeSymbol)) {
+ for (tp <- t.tpe if !treeTypes(tp) && !currentOwner.ownerChain.contains(tp.typeSymbol)) {
tp match {
case NoType | NoPrefix =>
case NullaryMethodType(_) =>
@@ -557,12 +557,17 @@ trait TypeDiagnostics {
def unsetVars = localVars filter (v => !setVars(v) && !isUnusedTerm(v))
}
- def apply(unit: CompilationUnit) = {
+ private def warningsEnabled: Boolean = {
+ val ss = settings
+ import ss._
+ warnUnusedPatVars || warnUnusedPrivates || warnUnusedLocals || warnUnusedParams || warnUnusedImplicits
+ }
+
+ def apply(unit: CompilationUnit): Unit = if (warningsEnabled) {
val p = new UnusedPrivates
p traverse unit.body
- val unused = p.unusedTerms
- unused foreach { defn: DefTree =>
- val sym = defn.symbol
+ for (defn: DefTree <- p.unusedTerms) {
+ val sym = defn.symbol
val pos = (
if (defn.pos.isDefined) defn.pos
else if (sym.pos.isDefined) sym.pos
@@ -591,10 +596,10 @@ trait TypeDiagnostics {
)
reporter.warning(pos, s"$why $what in ${sym.owner} is never used")
}
- p.unsetVars foreach { v =>
+ for (v <- p.unsetVars) {
reporter.warning(v.pos, s"local var ${v.name} in ${v.owner} is never set - it could be a val")
}
- p.unusedTypes foreach { t =>
+ for (t <- p.unusedTypes) {
val sym = t.symbol
val why = if (sym.isPrivate) "private" else "local"
reporter.warning(t.pos, s"$why ${sym.fullLocationString} is never used")