Scala Programming Language
  1. Scala Programming Language
  2. SI-6514

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

    Details

      Description

      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.

        Activity

        Hide
        Paul Phillips added a comment -

        > 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.

        Show
        Paul Phillips added a comment - > 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.
        Hide
        James Roper added a comment -

        No worries, that's a good enough short term solution for me.

        Show
        James Roper added a comment - No worries, that's a good enough short term solution for me.
        Show
        Jason Zaugg added a comment - https://github.com/scala/scala/pull/2111

          People

          • Assignee:
            Jason Zaugg
            Reporter:
            James Roper
          • Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development