summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2007-03-08 17:17:24 +0000
committerMartin Odersky <odersky@gmail.com>2007-03-08 17:17:24 +0000
commit0790935d101215532ef025c8da80f2e586a7acaf (patch)
tree35471cdfee6a82bca35db9f3c113cd87f92cfe87
parent3e35bb38883427cdbf8b93d0a29089c0dfe7fce9 (diff)
downloadscala-0790935d101215532ef025c8da80f2e586a7acaf.tar.gz
scala-0790935d101215532ef025c8da80f2e586a7acaf.tar.bz2
scala-0790935d101215532ef025c8da80f2e586a7acaf.zip
added option -Xwarndeadcode
-rw-r--r--src/compiler/scala/tools/nsc/CompilationUnits.scala10
-rw-r--r--src/compiler/scala/tools/nsc/Settings.scala1
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala12
3 files changed, 17 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/CompilationUnits.scala b/src/compiler/scala/tools/nsc/CompilationUnits.scala
index ad49327574..e76f95d207 100644
--- a/src/compiler/scala/tools/nsc/CompilationUnits.scala
+++ b/src/compiler/scala/tools/nsc/CompilationUnits.scala
@@ -40,14 +40,18 @@ trait CompilationUnits requires Global {
reporter.error(position(pos), msg)
}
- def warning(pos: int, msg: String) = reporter.warning(position(pos), msg)
+ def warning(pos: int, msg: String) =
+ if (!(errorPositions contains pos)) {
+ errorPositions += pos
+ reporter.warning(position(pos), msg)
+ }
def deprecationWarning(pos: int, msg: String) =
- if (settings.deprecation.value) reporter.warning(position(pos), msg)
+ if (settings.deprecation.value) warning(pos, msg)
else currentRun.deprecationWarnings = true
def uncheckedWarning(pos: int, msg: String) =
- if (settings.unchecked.value) reporter.warning(position(pos), msg)
+ if (settings.unchecked.value) warning(pos, msg)
else currentRun.uncheckedWarnings = true
def incompleteInputError(pos:int, msg:String) =
diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala
index ade73ab2bc..ee02445fc6 100644
--- a/src/compiler/scala/tools/nsc/Settings.scala
+++ b/src/compiler/scala/tools/nsc/Settings.scala
@@ -122,6 +122,7 @@ class Settings(error: String => unit) {
val inline = BooleanSetting("-Xinline", "Perform inlining when possible")
val Xcloselim = BooleanSetting("-Xcloselim", "Perform closure elimination")
val Xdce = BooleanSetting("-Xdce", "Perform dead code elimination")
+ val Xwarndeadcode = BooleanSetting("-Xwarndeadcode", "Emit warnings for dead code")
val XbytecodeRead = BooleanSetting("-XbytecodeRead", "Enable bytecode reader.")
val Xdetach = BooleanSetting("-Xdetach", "Perform detaching of remote closures")
val Xshowcls = StringSetting ("-Xshowcls", "class", "Show class info", "")
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 5962ef7d99..28431bf328 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -625,6 +625,9 @@ trait Typers requires Analyzer {
} else if (!context.undetparams.isEmpty && (mode & POLYmode) == 0) { // (9)
instantiate(tree, mode, pt)
} else if (tree.tpe <:< pt) {
+ if (settings.Xwarndeadcode.value &&
+ tree.tpe.symbol == AllClass && pt != WildcardType && pt.symbol != AllClass)
+ context.unit.warning (tree.pos, "dead code")
tree
} else {
if ((mode & PATTERNmode) != 0) {
@@ -652,8 +655,8 @@ trait Typers requires Analyzer {
// (13); the condition prevents chains of views
if (settings.debug.value) log("inferring view from "+tree.tpe+" to "+pt)
val coercion = inferView(tree.pos, tree.tpe, pt, true)
- // convert forward views of delegate types into closures wrapped around
- // the delegate's apply method (the "Invoke" method, which was translated into apply)
+ // convert forward views of delegate types into closures wrapped around
+ // the delegate's apply method (the "Invoke" method, which was translated into apply)
if (forMSIL && coercion != null && isCorrespondingDelegate(tree.tpe, pt)) {
val meth: Symbol = tree.tpe.member(nme.apply)
if(settings.debug.value)
@@ -1336,7 +1339,10 @@ trait Typers requires Analyzer {
case _ =>
val localTyper = if (inBlock || (stat.isDef && !stat.isInstanceOf[LabelDef])) this
else newTyper(context.make(stat, exprOwner))
- localTyper.typed(stat)
+ val stat1 = localTyper.typed(stat)
+ if (settings.Xwarndeadcode.value && stat1.tpe.symbol == AllClass)
+ context.unit.warning(stat1.pos, "dead code")
+ stat1
}
}
def accesses(accessor: Symbol, accessed: Symbol) =