-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Analyzer exhaustiveness-checking inconsistent for switch on record #52908
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
Comments
@johnniwinther I don't know who should look at this, but I'm hoping you know. |
I'll take a look at it. |
The problem is that the flow analysis uses the static type of the switch statement scrutinee to determine whether the switch is exhaustive. Because If the switch was written as a switch expression (which is always exhaustive) there is no problem in writing:
@pq @bwilkerson In this case we probably shouldn't report a lint about the unreachable case, but instead suggest adding a |
I'm surprised to learn that a switch statement's exhaustiveness status is determined only by the type of its argument, and not also by whether a |
With "a cc @munificent |
Well, that or it's in a conditional block that is itself the last statement of a non-void method, and so on. |
Yeah, this is a known annoying pain point. It's a consequence of the fact that we do flow analysis separate from exhaustiveness checking. In a perfect world, we'd do those as one holistic process and you wouldn't run into this situation. I'm going to close this as a dupe of dart-lang/language#2977 and we can resume the discussion there. The suggestion to treat a switch statement as always-exhaustive if it occurs in a position where a value must be returned is really interesting and one I honestly never considered. Thanks for bringing that up! |
This code:
produces this error with
dart analyze
on Dart 3.0.5:However, if I uncomment the
case (_, _):
I get this info instead:My expectation is that the first form should work, because it does exhaustively cover all possible cases of the input record. Regardless, it seems like the analyzer should at least be consistent about whether it considers this switch to be exhaustive or not.
The text was updated successfully, but these errors were encountered: