Closed
Description
The following code compiles without warning, even though the pattern isn't exhaustive:
object Main {
def foo(x: Option[Int]): Int = x match {
case Some(n) if n % 2 == 0 => n
case None => 0
}
def main(args: Array[String]): Unit = println(foo(Some(1)))
}
It looks like we special cases guards for redundancy checks but not for exhaustivity checks (https://github.com/lampepfl/dotty/blob/85ab20fd874994634b909f0883760413f6e2ef12/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala#L812), but we need to do both to be safe.
See also previous discussions in scala/bug#5365