Closed
Description
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