Check exhaustivity of any case class#22604
Conversation
| //> using options -deprecation -feature | ||
|
|
||
| abstract class Foo { | ||
| def bar(): Unit = this match { |
There was a problem hiding this comment.
Why doesn't bar also get a non-exhaustive warning as the baz below?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
So are you saying that baz shouldn't warn?
There was a problem hiding this comment.
Yes, because the two matching do look identical to me.
There was a problem hiding this comment.
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.
Fixes #22590