The following code defines an exhaustive match over a Vector
, v
.
def testExhaustiveness(v: Vector[Int]) = {
v match {
case Vector() => println("v is empty")
case ns :+ n => println("v has at least one element")
}
}
@main
def main = {
testExhaustiveness(Vector()) // v is empty
testExhaustiveness(Vector(1)) // v has at least one element
testExhaustiveness(Vector(1, 2)) // v has at least one element
}
However, the compiler gives [E029]
18 | v match {
| ^
|match may not be exhaustive.
|
|It would fail on pattern case: Vector(_, _*), Vector(_, _*), Vector(_, _*), Vector(_, _*), Vector(_, _*), Vector(_, _*)
|
| longer explanation available when compiling with `-explain`
I imagine this is in error. So, how can I get the compiler to recognise my exhaustive match? I understand we can suppress warnings with a pragma, but is there a destructuring that is accepted by the compiler?