Skip to content

Check exhaustivity of any case class #22604

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

Merged
merged 4 commits into from
Mar 3, 2025
Merged

Conversation

dwijnand
Copy link
Member

Fixes #22590

@dwijnand dwijnand marked this pull request as ready for review February 19, 2025 12:38
@dwijnand dwijnand requested a review from noti0na1 February 19, 2025 12:38
@@ -1,4 +1,4 @@
//> using options -Xfatal-warnings -deprecation -feature
//> using options -deprecation -feature

abstract class Foo {
def bar(): Unit = this match {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't bar also get a non-exhaustive warning as the baz below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Foo isn't sealed, we just don't run exhaustivity on it. But Tuple2 is sealed, so we do (and then comprehend that there are more possible values of Foo after Foo1 and Foo2)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree we shouldn't check exhaustivity for Foo. In this sense, the selector type is not sealed, then matching any subtype of it would be considered as "(maybe) covering the whole space".

Therefore, the tuple arguments should also cover the whole space. Tuple2 is sealed only means the tuple itself need to be covered, and the content should not be affected, so we should not check exhaustivity for the tuple arguments here as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So are you saying that baz shouldn't warn?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because the two matching do look identical to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hesitate to do that, as I fear it would be classified a "regression" that we're no longer warning there. I understand the position the dilemma, though.

@noti0na1 noti0na1 assigned dwijnand and unassigned noti0na1 Mar 3, 2025
@dwijnand dwijnand merged commit ab1bf38 into scala:main Mar 3, 2025
29 checks passed
@WojciechMazur WojciechMazur added this to the 3.7.0 milestone Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

failed to produce a warning about inexhaustive pattern
3 participants