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

Incorrect pattern match "unreachable" warning

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: Scala 2.9.0, Scala 2.10.0-M6
    • Fix Version/s: Scala 2.10.0
    • Component/s: Pattern Matcher
    • Labels:
    • Environment:

      mac os X lion

      Description

      abstract sealed trait AST
      abstract sealed trait AExpr                  extends AST
      case class AAssign(name: String, v: AExpr)   extends AExpr
      case class AConstBool(v: Boolean)            extends AExpr
      
      trait Ty {}
      case class TInt() extends Ty
      case class TBool() extends Ty
      
      object Foo {
        def checkExpr(ast: AExpr): Ty = {
          var astTy:Ty = ast match {
            case AAssign(nm: String, v:AExpr) => TBool() 
      
            case AConstBool(v: Boolean) => TBool() 
      
            case _                          => throw new Exception(s"Unhandled case check(ast: ${ast.getClass})")
          }
          astTy
        }
      }
      
      

      I get the following warning:

      Foo.scala:15: warning: unreachable code
            case AConstBool(v: Boolean) => TBool() 
                                                ^
      

      However if I remove just one type annotation, there's no problem:

        case AAssign(nm: String, v) => TBool() 
      

        Activity

        Hide
        Jason Zaugg added a comment -

        Marking as a duplicate of SI-6022. I have submitted this example as an additional test case: https://github.com/scala/scala/pull/2293

        Show
        Jason Zaugg added a comment - Marking as a duplicate of SI-6022 . I have submitted this example as an additional test case: https://github.com/scala/scala/pull/2293

          People

          • Assignee:
            Jason Zaugg
            Reporter:
            Sriram Srinivasan
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development