You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"Add missing case clauses" only inserts first case for switch pattern statements #52180
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).
changed the title [-]"Add missing case clauses" does not work correctly for switch pattern statements[/-][+]"Add missing case clauses" only inserts first case for switch pattern statements[/+]on Apr 26, 2023
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.
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.
It fails because of "Unnecessary error filter" (a test bug), but if I remove the WithFilter, it fails with:
Expected to find fix dart.fix.add.missingEnumCaseClauses in
Fix(kind=dart.fix.add.missingSwitchCases, change={"message":"Add missing switch cases","edits":[{"file":"C:\home\test\lib\test.dart","fileStamp":0,"edits":[{"offset":49,"length":0,"replacement":" case E.a:\r\n // TODO: Handle this case.\r\n case E.b:\r\n // TODO: Handle this case.\r\n case E.c:\r\n // TODO: Handle this case.\r\n"}]}],"linkedEditGroups":[],"id":"dart.fix.add.missingSwitchCases"})
It looks like the fix provided is dart.fix.add.missingSwitchCases but this test is for dart.fix.add.missingEnumCaseClauses. It's not clear to me what the difference is here (I thought maybe one is for the original switch statement parsing and the other is since switch expressions were added, but I don't think that explains how any of other other tests in this class would be passing).
Oh, as I was about to send this I noticed all the non-failing tests in that class are marked // @dart=2.19.
So.. should all of the @FailingTests in the class AddMissingEnumCaseClausesTest now be moved into AddMissingSwitchCasesTest_SwitchStatement since it seems for >2.19 they'll all be handled by that fix instead?
The fix kind DartFixKind.ADD_MISSING_ENUM_CASE_CLAUSES is associated with AddMissingEnumCaseClauses, which is associated with StaticWarningCode.MISSING_ENUM_CONSTANT_IN_SWITCH. That warning code is produced only in pre-pattern-enabled code.
The fix kind DartFixKind.ADD_MISSING_SWITCH_CASES is associated with AddMissingSwitchCases, which is associated with both CompileTimeErrorCode.NON_EXHAUSTIVE_SWITCH_EXPRESSION and CompileTimeErrorCode.NON_EXHAUSTIVE_SWITCH_STATEMENT, both of which are only produced in pattern-enabled code.
... should all of the @FailingTests in the class AddMissingEnumCaseClausesTest now be moved into AddMissingSwitchCasesTest since it seems for >2.19 they'll all be handled by that fix instead?
If the tests are intended to be run with patterns enabled, then yes, they should be moved because they will produce the CompileTimeErrorCode.NON_EXHAUSTIVE_SWITCH_EXPRESSION and CompileTimeErrorCode.NON_EXHAUSTIVE_SWITCH_STATEMENT diagnostics, and AddMissingSwitchCasesTest is where those tests should live.
Activity
[-]"Add missing case clauses" does not work correctly for switch pattern statements[/-][+]"Add missing case clauses" only inserts first case for switch pattern statements[/+]bwilkerson commentedon Apr 26, 2023
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.
@scheglov
deimantasa commentedon May 21, 2023
Any updates to this? It feels like a serious bummer, especially when having several (5+) enum cases to deal with. Auto-fill used to save tons of time.
P.S. Android Studio (Flamingo) does not even generate one case. Only by hovering, first case is hinted.


pq commentedon Jul 6, 2023
@scheglov?
lhengl commentedon Jul 12, 2023
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.
AbdulazizRasulbek commentedon Jul 12, 2023
same issue for sealed classes
bwilkerson commentedon Jun 13, 2024
This has been fixed by https://dart-review.googlesource.com/c/sdk/+/371062 and should be available in the next stable release.
DanTup commentedon Jun 13, 2024
@bwilkerson I tested this and it seems to work great 🥳 but I noticed the test I linked up top is still marked
@FailingTest: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
WithFilter, it fails with:It looks like the fix provided is
dart.fix.add.missingSwitchCasesbut this test is fordart.fix.add.missingEnumCaseClauses. It's not clear to me what the difference is here (I thought maybe one is for the original switch statement parsing and the other is since switch expressions were added, but I don't think that explains how any of other other tests in this class would be passing).Oh, as I was about to send this I noticed all the non-failing tests in that class are marked
// @dart=2.19.So.. should all of the
@FailingTestsin the classAddMissingEnumCaseClausesTestnow be moved intoAddMissingSwitchCasesTest_SwitchStatementsince it seems for >2.19 they'll all be handled by that fix instead?bwilkerson commentedon Jun 13, 2024
The fix kind
DartFixKind.ADD_MISSING_ENUM_CASE_CLAUSESis associated withAddMissingEnumCaseClauses, which is associated withStaticWarningCode.MISSING_ENUM_CONSTANT_IN_SWITCH. That warning code is produced only in pre-pattern-enabled code.The fix kind
DartFixKind.ADD_MISSING_SWITCH_CASESis associated withAddMissingSwitchCases, which is associated with bothCompileTimeErrorCode.NON_EXHAUSTIVE_SWITCH_EXPRESSIONandCompileTimeErrorCode.NON_EXHAUSTIVE_SWITCH_STATEMENT, both of which are only produced in pattern-enabled code.If the tests are intended to be run with patterns enabled, then yes, they should be moved because they will produce the
CompileTimeErrorCode.NON_EXHAUSTIVE_SWITCH_EXPRESSIONandCompileTimeErrorCode.NON_EXHAUSTIVE_SWITCH_STATEMENTdiagnostics, andAddMissingSwitchCasesTestis where those tests should live.Move tests for switch enum cases for >= 2.19 from `AddMissingEnumCase…