-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 unreachable and exhaustiveness warnings for large tuples #19084
Comments
This will be a huge problem for named tuples. Previously very few people would write a large tuple pattern like this. But with named tuple patterns, all it takes is: case (name = "Bob", age = a) and the wrong unreachable warning will also pop up. |
Another variant: There's no need to actually match on a tuple element. The following will also issue the wrong warning even though the tuple consists only of pattern variables.
|
Extracted from the named tuples PR, where it allowed the correct typing of ```scala val bob = ( x0 = 0, x1 = 0, x2 = 0, x3 = 0, x4 = 0, x5 = 0, x6 = 0, x7 = 0, x8 = 0, x9 = 0, name = "Bob", y1 = 0, age = 33, y2 = 0, z0 = 0, z1 = 0, z2 = 0, z3 = 0, z4 = 0, z5 = 0, z6 = 0, z7 = 0, z8 = 0, z9 = 0) bob match case p @ (name = "Bob", age = a) => p,age ``` The problem was that `p` was typed before as `<some large tuple type> & TupleXXL` and that prevented the correct analysis of tuple elements. I am submitting this as a separate PR since it might also be relevant for #19084.
is this fixed by #19085 ? |
No, it's independent. |
This issue was picked for the Issue Spree No. 40 of December 5th, 2023 which takes place in 6 days. @dwijnand, @natsukagami, @iusildra will be working on it. If you have any insight into the issue or guidance on how to fix it, please leave it here. |
Found some of my notes in #14588 (comment) We were able to find an initial, quickfix, for reachability, by special casing TupleXXL in isSubType: else tp2 match
case tp2: TypeRef if tp2.symbol == defn.TupleXXLClass && tp1.tupleElementTypes.isDefined => true // arity?
case _ => tp1 <:< tp2 Necessary because TypeComparer doesn't consider 23 ints to be a subtype of TupleXXL (which the pattern is typed as). Unfortunately that doesn't help exhaustivity. In exhaustivity we try to calculate the Space of values that remains once all case patterns are considered. Using the test case in #16657, the pattern uses TupleXXL.unapplySeq, and is type cast to |
Compiler version
3.4.0 RC1
Minimized example
Output
Expectation
If I run the program it does get into the case and print the correct value.
Variant: If I drop the last case
case _ => assert(false)
, I get this instead:The text was updated successfully, but these errors were encountered: