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
Missing exhaustivity warning on ints (and other switchable types) #12247
Comments
agree this is a bug. a weird thing here is that if you add another clause, the checking comes back! scala 2.13.4> def test(i: Int) = i match {
| case value if value < 0 => true
| case value if value > 10 => false
| case 5 => true
| }
^
warning: match may not be exhaustive. |
So
Why is that? Because it can be emitted by a switch, so it doesn't do any analysis, because analysis was for those non-switchable sealed types! I'll try to fix this for the next release. I'll also try to suss out what it is about |
I have a branch where I got this working. But making switchable types emit warnings fixes this and then highlights all the times (e.g. in the compiler) where internal implementations are switching on ints because of how fast it is, for the (let's say) 6 ints that are tracked internally. I think I ran out of steam/patience to fix all the cases in the compiler before I gave myself a break and considered that this might be just bad idea... |
could something like an annotation
In the case of switch matches, you commonly want to use a type that allows for more values than your domain, because you're restricted by performance considerations. Maybe it makes sense to combine the annotation for not caring about non-exhaustiveness and the annotation for caring about the switch performance. |
Can we reuse
(I say int but I mean any switchable type: byte, short, int, char, String.) I think the second one is easier: if you're not using a switch table and you've got an incomplete match, then |
Figuring out what I mean exactly: I always want exhaustiveness checks on the domain of the match, but I can't always communicate the domain to the compiler. Even if I can't, I may still want the compiler to warn you that you don't have a default case. But maybe that's uncommon enough to either not support it, or to support it with a new opt-in annotation. As for concrete answers to your questions:
For the second maybe For the first, maybe it's enough to suck it up and don't have exhaustiveness checking even though you would prefer it, maybe introduce, I don't know, |
related: #12770 |
Do my expectations (for a warning if it can prove inexhaustivity) change if the expected type is a partial function? Also, I haven't kept up with the latest on Dotty, but probably innovation must start there. |
reproduction steps
Scala 2.13.4 is supposed to implement the following:
(Source)
Yet, the following code compiles without warning:
This has been tried with and without the
-Xlint:strict-unsealed-patmat
scalac option.problem
The way I understand the quoted sentence is: the compiler will consider both branches of the pattern match as potentially being
false
at the same time, which will cause it to emit a non-exhaustivity warning.This is not what's happening.
The text was updated successfully, but these errors were encountered: