Skip to content

Missing "unreachable code" warning when adding case after unfalsifiable extractor #4225

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

Closed
smarter opened this issue Apr 1, 2018 · 1 comment

Comments

@smarter
Copy link
Member

smarter commented Apr 1, 2018

The following code produces no warning, even though the case _ is unreachable since Bar returns an instance of Some (scalac correctly produces a warning here):

object Bar {
  def unapply(x: Int): Some[Int] =
    Some(0)
}

object Test {
  def test(x: Int) =
    x match {
      case Bar(a) => a
      case _ => x // should be unreachable
    }
}

Interestingly, if we replace Int by a sealed trait, we do produce a warning:

sealed trait Base
case class One() extends Base
object Foo {
  def unapply(x: Base): Some[Int] =
    Some(0)
}

object Test {
  def test(x: Base) =
    x match {
      case Foo(a) => a
      case _ => x
    }
}
-- [E030] Match case Unreachable Warning: try/some.scala:12:13 -----------------
12 |      case _ => x
   |             ^^^^
   |             unreachable code
@liufengyun
Copy link
Contributor

Currently we do reachability check conditionally as that of exhaustivity check. I'll change it to always do reachability check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants