Skip to content
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

Wrong exhaustivity warning for XXL tuples #14588

Closed
pweisenburger opened this issue Feb 28, 2022 · 2 comments · Fixed by #19212
Closed

Wrong exhaustivity warning for XXL tuples #14588

pweisenburger opened this issue Feb 28, 2022 · 2 comments · Fixed by #19212

Comments

@pweisenburger
Copy link
Contributor

Compiler version

3.1.1

Minimized code

(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23) match
  case (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22, x23) =>

Output

-- [E029] Pattern Match Exhaustivity Warning:
12 |    (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23) match
   |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |match may not be exhaustive.
   |
   |It would fail on pattern case: _: *:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,*:[Int,EmptyTuple]]]]]]]]]]]]]]]]]]]]]]]

Expectation

I think the compiler is wrong. The match would not fail on this pattern.

There is no warning for non-XXL tuples.

@pweisenburger pweisenburger added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 28, 2022
@dwijnand
Copy link
Member

dwijnand commented Mar 1, 2022

This fails because match analysis uses subtyping, and with a unapply of TupleXXL and a scrutinee of an XXL generic tuple type, subtyping returns:

    ==> (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) <:< scala.runtime.TupleXXL?
    <== (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) <:< scala.runtime.TupleXXL = false

@odersky @nicolasstucki should we add this to how subtyping is handling generic tuples? I'm also wondering whether it's worth the time to try to unpick the tuple vs generic tuple subtyping relationship... and try to do it more correctly.

@dwijnand dwijnand added area:typer stat:needs triage Every issue needs to have an "area" and "itype" label and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 1, 2022
@dwijnand dwijnand self-assigned this Mar 1, 2022
@dwijnand dwijnand removed the stat:needs triage Every issue needs to have an "area" and "itype" label label Mar 7, 2022
@dwijnand
Copy link
Member

dwijnand commented Mar 7, 2022

There's a shared belief that TupleXXL.unapplySeq shouldn't be the unapply symbol, because TupleXXL should only exist after Erasure (PatternMatcher is before). But Typer's typedTuple does use TupleXXL. Now that might be because we didn't have what we have now in Tuple.scala. But also because the only unapply we have is *:.unapply which only deconstructs head and tail. So maybe we can add a Tuple.unapplySeq(x: Tuple): Option[Seq[Any]] and use that instead in Typer, but provided we switch small arities to be efficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants