-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
"Add missing case clauses" only inserts first case for switch pattern statements #52180
Comments
Unfortunately, that behavior is the best we can do at the moment. With the switch to patterns we had to write a much more general algorithm to compute exhaustiveness, and that algorithm currently only finds the first case that isn't covered. There have been discussions about extending the algorithm to find all of the missing cases so that we can do a better job, but I don't know what the state of that work is. |
|
Just upgraded to dart 3 and stumbled into this problem. There used to be fixes available for exhaustiveness, now there isn't. With the prevalent use of enum and switch statements, I'm surprised this issue doesn't have more upvotes. |
same issue for sealed classes |
This has been fixed by https://dart-review.googlesource.com/c/sdk/+/371062 and should be available in the next stable release. |
@bwilkerson I tested this and it seems to work great 🥳 but I noticed the test I linked up top is still marked sdk/pkg/analysis_server/test/src/services/correction/fix/add_missing_enum_case_clauses_test.dart Line 41 in 498dcc0
It fails because of "Unnecessary error filter" (a test bug), but if I remove the
It looks like the fix provided is Oh, as I was about to send this I noticed all the non-failing tests in that class are marked So.. should all of the |
The fix kind The fix kind
If the tests are intended to be run with patterns enabled, then yes, they should be moved because they will produce the |
…ClausesTest` to `AddMissingSwitchCasesTest_SwitchStatement` The tests in this class were duplicated when pattern support was added, one set of tests for <= 2.19 and one for > 2.19. The> 2.19 tests were marked as Failing because this functionality didn't work. This functionality has now been implemented, but because the error code and fix are different, these tests continued to fail. This change moves the tests to the equivalent pattern-enabled fixes tests and removes `@FailingTest` for those that can now pass. There are still a few marked `@FailingTest` because of differences in the new implementation. See #52180 (comment) Change-Id: Ie1dfa5bc5c608d38a191507f5f0403d20ba2ef31 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371684 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Sam Rawlins <srawlins@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
With language version 2.19 this works correctly:
But for 3.0 it only inserts one case:
This missing test might be related, though it seems to be looking for a different fix to the one being produced (perhaps it's intended for pre-3.0 code, but probably it shouldn't be failing if that's the case).
sdk/pkg/analysis_server/test/src/services/correction/fix/add_missing_enum_case_clauses_test.dart
Line 41 in 498dcc0
The text was updated successfully, but these errors were encountered: