diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 9 | ||||
-rw-r--r-- | test/files/neg/check-dead.check | 7 | ||||
-rw-r--r-- | test/files/neg/check-dead.flags | 1 | ||||
-rw-r--r-- | test/files/neg/check-dead.scala | 34 |
4 files changed, 48 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 8ce26c92a1..0f87d6ba33 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1791,7 +1791,7 @@ trait Typers { self: Analyzer => if (meth.isPrimaryConstructor && meth.isClassConstructor && phase.id <= currentRun.typerPhase.id && !reporter.hasErrors) computeParamAliases(meth.owner, vparamss1, rhs1) - if (tpt1.tpe.typeSymbol != NothingClass && !context.returnsSeen) rhs1 = checkDead(rhs1) + if (tpt1.tpe.typeSymbol != NothingClass && !context.returnsSeen && rhs1.tpe.typeSymbol != NothingClass) rhs1 = checkDead(rhs1) if (phase.id <= currentRun.typerPhase.id && meth.owner.isClass && meth.paramss.exists(ps => ps.exists(_.hasDefaultFlag) && isRepeatedParamType(ps.last.tpe))) @@ -2205,8 +2205,11 @@ trait Typers { self: Analyzer => else checkNoDoubleDefsAndAddSynthetics(result) } - def typedArg(arg: Tree, mode: Int, newmode: Int, pt: Type): Tree = - checkDead(constrTyperIf((mode & SCCmode) != 0).typed(arg, mode & stickyModes | newmode, pt)) + def typedArg(arg: Tree, mode: Int, newmode: Int, pt: Type): Tree = { + val t = constrTyperIf((mode & SCCmode) != 0).typed(arg, mode & stickyModes | newmode, pt) + if ((newmode & BYVALmode) != 0) t + else checkDead(t) + } def typedArgs(args: List[Tree], mode: Int) = args mapConserve (arg => typedArg(arg, mode, 0, WildcardType)) diff --git a/test/files/neg/check-dead.check b/test/files/neg/check-dead.check new file mode 100644 index 0000000000..be4de3060b --- /dev/null +++ b/test/files/neg/check-dead.check @@ -0,0 +1,7 @@ +check-dead.scala:27: error: dead code following this construct + throw new Exception + ^ +check-dead.scala:31: error: dead code following this construct + throw new Exception + ^ +two errors found diff --git a/test/files/neg/check-dead.flags b/test/files/neg/check-dead.flags new file mode 100644 index 0000000000..c7d406c649 --- /dev/null +++ b/test/files/neg/check-dead.flags @@ -0,0 +1 @@ +-Ywarn-dead-code -Xfatal-warnings
\ No newline at end of file diff --git a/test/files/neg/check-dead.scala b/test/files/neg/check-dead.scala new file mode 100644 index 0000000000..851e81d886 --- /dev/null +++ b/test/files/neg/check-dead.scala @@ -0,0 +1,34 @@ +package dummy + +object Error { + def soSorry(msg: String = "sorry"): Nothing = + throw new Exception("we have a problem: "+msg) +} + +class NoDeads { + def x = synchronized { throw new Exception } + def y[T](arg: T) = println("foo") + def z = this.y(throw new Exception) + + def dummy1: Int = synchronized { + val i = 10 + 2 + return i + } + def dummy1b: Int = synchronized { + val i = 10 + 2 + i + } + + def dummy2: String = Error.soSorry("we're dummies") +} + +class Deads { + def x1 = synchronized { + throw new Exception + 5 * 5 + } + def x2: Int = synchronized { + throw new Exception + return 5 + } +}
\ No newline at end of file |