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

Fix exhaustivity uncheckableType's logic for tuples #9163

Merged
merged 1 commit into from Sep 7, 2020

Conversation

dwijnand
Copy link
Member

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.

Fixes scala/bug#10373

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.
@scala-jenkins scala-jenkins added this to the 2.12.13 milestone Aug 11, 2020
@dwijnand dwijnand added the release-notes worth highlighting in next release notes label Aug 11, 2020
@dwijnand
Copy link
Member Author

(Not hugely release-note-able, but perhaps it can be linked as a minor fix in the same area.)

@lrytz
Copy link
Member

lrytz commented Aug 18, 2020

Why do we have special treatment of tuples in the first place?

If I define my own T2 tuple case class, the example gives

<console>:26: warning: match may not be exhaustive.
It would fail on the following input: T2((x: Foo forSome x not in (Foo_1, Foo_2)), _)
           def blitz(that: Foo): Unit = T2(this, that) match {
                                          ^

also after this PR. Is that expected?

@dwijnand
Copy link
Member Author

Why do we have special treatment of tuples in the first place?

Not 100% sure - because it was common and was fixed to do something appropriate, I guess? Then it broke 😄

also after this PR. Is that expected?

Not in my eyes.

@dwijnand
Copy link
Member Author

dwijnand commented Sep 2, 2020

I can't put together a generalisation of this for any case class (i.e. any Product extending class). I think this is, again, tied to null: if we didn't disable the null modelling (like patmat's Logic was original built to) I think it would say It would fail on the following input: T2(null, _) instead, and (null, _) for tuples.

So I'm going to stop here. I'm happy for this to be merged, merged but keeping scala/bug#10373 open for the T2 custom case class, merged and opening another ticket for T2, or closed without merging.

Copy link
Member

@lrytz lrytz left a 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?

@lrytz lrytz merged commit 24f3c54 into scala:2.12.x Sep 7, 2020
@dwijnand dwijnand deleted the exhaust-tuple-unsealed-false-positive branch September 7, 2020 11:33
finaglehelper pushed a commit to twitter/util that referenced this pull request Jan 29, 2021
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes
Projects
None yet
3 participants