sealed trait A
case object A1 extends A
case object A2 extends A
sealed trait T { def a: A }
object T { def unapply(t: T): Some[A] = Some(t.a) }
case class T1(x: Int) extends T { def a = A1 }
case class T2(x: Int) extends T { def a = A2 }
object Test {
def m(t: T) = t match {
case T(A1) => 0
// case T(A2) => 1
}
}
Exhaustivity can correctly identify the (in)completeness of the match, but the counter-examples in the warning message are misleading.
➜ sandbox sc Test.scala
Test.scala:10: warning: match may not be exhaustive.
It would fail on the following inputs: T1(_), T2(_)
def m(t: T) = t match {
^
1 warning
Exhaustivity can correctly identify the (in)completeness of the match, but the counter-examples in the warning message are misleading.