Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dead code warning in case statement when throwing an exception returned by a method call #6514

Closed
scabug opened this issue Oct 11, 2012 · 4 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Oct 11, 2012

I found similar reports to this elsewhere, but they seemed to be marked as resolved in an older version of Scala, so this seems to be a new issue.

$ scala -Ywarn-dead-code
Welcome to Scala version 2.10.0-M7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_35).
Type in expressions to have them evaluated.
Type :help for more information.

scala> def e(msg: String) = new Exception(msg)
e: (msg: String)Exception

scala> def a(b: Boolean) = {
     |   b match {
     |     case true => throw e("true")
     |     case false => throw e("false")
     |   }
     | }
<console>:10: warning: dead code following this construct
           case true => throw e("true")
                        ^
<console>:11: warning: dead code following this construct
           case false => throw e("false")
                         ^
a: (b: Boolean)Nothing

This doesn't happen if I replace e with new Exception.

As an aside, is -Ywarn-dead-code going to be enabled by default along with -Xlint in 2.10 final? I saw some mention by Paul Phillips in another ticket of a branch that got rid of it, but that branch no longer exists and none of the tickets that were referring to it are closed yet, so I've got no idea what the status of that is. The warning is quite helpful, helped me find lots of dead code in Play, but there are lots of spurious warnings, I don't know if I should be reporting them or ignoring them... it can be a lot of effort to try and replicate some of the complex cases in the repl so that I can create a good bug report.

@scabug
Copy link
Author

@scabug scabug commented Oct 11, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6514?orig=1
Reporter: @jroper
Affected Versions: 2.10.0-M7

@scabug
Copy link
Author

@scabug scabug commented Oct 11, 2012

@paulp said:

As an aside, is -Ywarn-dead-code going to be enabled by default along with -Xlint in 2.10 final?

Nope. As you've noticed, it has become super noisy and it isn't a high enough priority for me to fix it soon.

@scabug
Copy link
Author

@scabug scabug commented Oct 11, 2012

@jroper said:
No worries, that's a good enough short term solution for me.

@scabug
Copy link
Author

@scabug scabug commented Feb 10, 2013

@scabug scabug closed this Feb 11, 2013
@scabug scabug added this to the 2.10.2-RC1 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants