Skip to content

Unexpected list of failing pattern cases in non-exhaustivity-warning #13932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ansvonwa opened this issue Nov 12, 2021 · 3 comments
Open

Unexpected list of failing pattern cases in non-exhaustivity-warning #13932

ansvonwa opened this issue Nov 12, 2021 · 3 comments

Comments

@ansvonwa
Copy link
Member

Compiler version

3.0.0, 3.1.0, 3.1.1-RC1, 3.1.2-RC1-bin-20211102-82172ed-NIGHTLY

Minimized code

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 
class scala.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?

@ansvonwa
Copy link
Member Author

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 Foo 
class scala.collection.immutable.Vector0$

@KacperFKorban
Copy link
Member

Can be related to #13931

@dwijnand
Copy link
Member

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:

  1. 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(_, _).
  2. Remove the cut off on counter examples?
  3. Make subclasses (and thus counter-exampes) iterate in declaration or name order, rather than Vector1 looking like it's intentionally not mentioned.
  4. Have a way to define the arity of subclasses, such that the exhaustivity checker could use that information (a language improvement).

@dwijnand dwijnand removed their assignment Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants