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

Incorrect pattern match "unreachable" warning #6210

Closed
scabug opened this issue Aug 9, 2012 · 2 comments
Closed

Incorrect pattern match "unreachable" warning #6210

scabug opened this issue Aug 9, 2012 · 2 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Aug 9, 2012

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() 
@scabug
Copy link
Author

@scabug scabug commented Aug 9, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6210?orig=1
Reporter: Sriram Srinivasan (sriram.srinivasan)
Affected Versions: 2.9.0, 2.10.0-M6

@scabug
Copy link
Author

@scabug scabug commented Mar 23, 2013

@retronym said:
Marking as a duplicate of #6022. I have submitted this example as an additional test case: scala/scala#2293

@scabug scabug closed this Mar 23, 2013
@scabug scabug added this to the 2.10.0 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