Skip to content

Commit babca33

Browse files
FMorschelCommit Queue
authored andcommitted
[DAS] Convert to switch statement considers operator
Fixes: #60429 Change-Id: Ie3fa5b9ed1fa9677017a694144b0809ba47c284a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420841 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Phil Quitslund <[email protected]> Auto-Submit: Felipe Morschel <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent 0c17d7f commit babca33

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

pkg/analysis_server/lib/src/services/correction/dart/convert_to_switch_statement.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,9 @@ class ConvertSwitchExpressionToSwitchStatement
394394
switchExpression: switchExpression,
395395
builder: builder,
396396
indent: indent,
397-
beforeCaseExpression: '${variableId.token.lexeme} = ',
397+
beforeCaseExpression:
398+
'${variableId.token.lexeme} '
399+
'${assignment.operator.lexeme} ',
398400
semicolon: semicolon,
399401
);
400402
});

pkg/analysis_server/test/src/services/correction/assist/convert_to_switch_statement_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,29 @@ int f(int x) {
521521
''');
522522
}
523523

524+
Future<void> test_operatorAssignment() async {
525+
await resolveTestCode('''
526+
void f(int x) {
527+
int v = 0;
528+
v += switch (x) {
529+
0 => 0,
530+
_ => 1,
531+
};
532+
}
533+
''');
534+
await assertHasAssistAt('switch', '''
535+
void f(int x) {
536+
int v = 0;
537+
switch (x) {
538+
case 0:
539+
v += 0;
540+
default:
541+
v += 1;
542+
}
543+
}
544+
''');
545+
}
546+
524547
Future<void> test_returnStatement() async {
525548
await resolveTestCode('''
526549
int f(int x) {

0 commit comments

Comments
 (0)