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

Compiler incorrectly reports unreachable code after List() pattern

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Trivial Trivial
    • Resolution: Fixed
    • Affects Version/s: Scala 2.9.1
    • Fix Version/s: Scala 2.10.0
    • Component/s: Pattern Matcher
    • Labels:
      None

      Description

      I don't think the following code should produce a compiler error:

      scala> (Vector(): Seq[_]) match { case List() => true; case Nil => false }}}
      <console>:8: error: unreachable code
                    (Vector(): Seq[_]) match { case List() => true; case Nil => false }
                                                                                ^
      

      The following slightly modified version seems to show that the false can be reached:

      scala> (Vector(): Seq[_]) match { case List() => true; case x if x == Nil => false }
      warning: there were 1 unchecked warnings; re-run with -unchecked for details
      res1: Boolean = false
      

      See also this Stack Overflow question.

        Activity

        Hide
        Jason Zaugg added a comment -

        Fixed by virtpatmat in 2.10, test case pending merge:

        https://github.com/scala/scala/pull/539

        Show
        Jason Zaugg added a comment - Fixed by virtpatmat in 2.10, test case pending merge: https://github.com/scala/scala/pull/539
        Hide
        Jason Zaugg added a comment -

        Needs a bit more thought, see Adriaans comments in the pull request.

        Show
        Jason Zaugg added a comment - Needs a bit more thought, see Adriaans comments in the pull request.
        Hide
        Jason Zaugg added a comment -

        After a brief doubletake triggered by the unintuitive case Nil vs case List, I'm back in the "this ticket is closed" camp.

        Show
        Jason Zaugg added a comment - After a brief doubletake triggered by the unintuitive case Nil vs case List , I'm back in the "this ticket is closed" camp.

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Travis Brown
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development