You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
objectSeqMatchTest {
defmain(args: Array[String]):Unit= {
deftest(seq: Seq[_]):Unit= seq match {
caseSeq() => println(s"$seq is empty")
caseSeq(_, _ @_*) => println(s"$seq has one or more elements")
// case _ => println(s"$seq is never matched")
}
test(Seq())
test(Seq(1))
test(Seq(1, 2))
test(Seq(1, 2, 3))
}
}
Problem
When compiled with no lints, the above code compiles with no warnings and runs correctly.
When compiled with -Xlint:strict-unsealed-patmat it produces the warning:
match may not be exhaustive.
It would fail on the following input: (x: Seq[?] forSome x not in Nil)
def test(seq: Seq[_]): Unit = seq match {
Using case _ +: _ exhibits the same problem. Uncommenting the wildcard case allows compilation with no warnings.
This seems incorrect, in that it's evident when run that all the possible Seq cases are matched.
The same test case using List with the same patterns also fails, but classic List cons patterns do not exhibit the problem.
The text was updated successfully, but these errors were encountered:
On reflection, I might be expecting too much of the compiler here, as it probably lacks enough information to know that these cases are exhaustive - the warning is "may not be exhaustive" after all, but the fact that there's a case that seems to obviously match the proposed failure pattern seems slightly jarring.
Uh oh!
There was an error while loading. Please reload this page.
Reproduction steps
Scala version: 2.13.10
Compile with
-Xlint:strict-unsealed-patmat
Problem
When compiled with no lints, the above code compiles with no warnings and runs correctly.
When compiled with
-Xlint:strict-unsealed-patmat
it produces the warning:Using
case _ +: _
exhibits the same problem. Uncommenting the wildcard case allows compilation with no warnings.This seems incorrect, in that it's evident when run that all the possible Seq cases are matched.
The same test case using
List
with the same patterns also fails, but classicList
cons patterns do not exhibit the problem.The text was updated successfully, but these errors were encountered: