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
Vector() match {
case v @Seq() => println(v.getClass)
}
(Same as in #13931 without the case _ =>. Related problems?)
Output
[warn] 3|Vector() match {
[warn] |^^^^^^^^
[warn] |match may not be exhaustive.
[warn] |
[warn] |It would fail on pattern case:Vector0, _: Vector2[Nothing], _: Vector3[Nothing], _: Vector4[Nothing], _: Vector5[Nothing], _: Vector6[Nothing]
[warn] |(More unmatched cases are elided)
[warn] one warning found
[warn] one warning found
[info] running run
classscala.collection.immutable.Vector0$
Expectation
Vector0 not being in the list of "failing" patterns, as the empty Vector() is matched.
Instead, _: Vector1[Nothing] should be there?
The text was updated successfully, but these errors were encountered:
In Scala 2.13.7, Vector1() is contained in the list as expected, but also Vector0:
[warn] .../src/main/scala/Foo.scala:3:11:match may not be exhaustive.
[warn] It would fail on the following inputs: Vector0, Vector1(), Vector2(), Vector3(), Vector4(), Vector5(), Vector6()
[warn] Vector() match {
[warn] ^
[warn] one warning found
[info] running Fooclassscala.collection.immutable.Vector0$
There's no knowledge in the types or the trees that could inform the compiler that Vector0 is covered by the use of Seq(). And Vector1 is missing because it's not in the first subclasses, and the exhaustivity checker only ever shows 6 counter examples in Scala 3.
So this is working as expected, but you could argue and someone might want to improve the status quo, on the following things:
When exhaustivity fails due to arity (and only arity, I think is necessary) then present counter examples based on arity, i.e. It would fail on pattern case: Seq(_), Seq(_, _).
Remove the cut off on counter examples?
Make subclasses (and thus counter-exampes) iterate in declaration or name order, rather than Vector1 looking like it's intentionally not mentioned.
Have a way to define the arity of subclasses, such that the exhaustivity checker could use that information (a language improvement).
Compiler version
3.0.0
,3.1.0
,3.1.1-RC1
,3.1.2-RC1-bin-20211102-82172ed-NIGHTLY
Minimized code
(Same as in #13931 without the
case _ =>
. Related problems?)Output
Expectation
Vector0
not being in the list of "failing" patterns, as the emptyVector()
is matched.Instead,
_: Vector1[Nothing]
should be there?The text was updated successfully, but these errors were encountered: