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
Fix exhaustivity uncheckableType's logic for tuples #9163
Fix exhaustivity uncheckableType's logic for tuples #9163
Conversation
As tuples (e.g. Tuple2) are case classes, for which `enumerateSubtypes` returns `List(List(tp))` therefore making it "checkable", any tuple type was accidentally always passing (or at least it has since that `isCase` branch was added to `enumerateSubtypes`). This was leading to false positives in the exhaustivity checking, as a tuple of non-sealed types was being deemed inexhaustive with a wildcard `(_, _)` counter-example.
(Not hugely release-note-able, but perhaps it can be linked as a minor fix in the same area.) |
Why do we have special treatment of tuples in the first place? If I define my own
also after this PR. Is that expected? |
Not 100% sure - because it was common and was fixed to do something appropriate, I guess? Then it broke 😄
Not in my eyes. |
I can't put together a generalisation of this for any case class (i.e. any So I'm going to stop here. I'm happy for this to be merged, merged but keeping scala/bug#10373 open for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 happy to merge this fix. Can you log a new ticket for the custom case class case?
Problem Supporting latest https://github.com/scala/scala/releases/tag/v2.12.13 includes a feature change in the scala compiler that will fail to compile when case matching is not exhaustive on tuples. Issues - scala/bug#10680 - scala/bug#10373 - scala/bug#10019 Resolved - scala/scala#9163 - scala/scala#9147 Solution Add `case _ => throw new MatchError` to case matching statement that is non-exhaustive JIRA Issues: SCALA-25 Differential Revision: https://phabricator.twitter.biz/D609046
As tuples (e.g. Tuple2) are case classes, for which
enumerateSubtypes
returns
List(List(tp))
therefore making it "checkable", any tuple typewas accidentally always passing (or at least it has since that
isCase
branch was added to
enumerateSubtypes
). This was leading to falsepositives in the exhaustivity checking, as a tuple of non-sealed types
was being deemed inexhaustive with a wildcard
(_, _)
counter-example.Fixes scala/bug#10373