Skip to content

Commit 79b9cce

Browse files
fshcheglovCommit Queue
authored andcommitted
Make the quick fix for replacing final with var work for if/case
Change-Id: Id1fa1626aab3459aa1dfbf75d29b7d758ca8f59c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/450000 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 5162a3d commit 79b9cce

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class ReplaceFinalWithVar extends ResolvedCorrectionProducer {
3030
VariableDeclarationList node => (node.keyword, node.type),
3131
PatternVariableDeclaration node => (node.keyword, null),
3232
DeclaredIdentifier node => (node.keyword, node.type),
33+
DeclaredVariablePattern node => (node.keyword, node.type),
3334
_ => (null, null),
3435
};
3536

pkg/analysis_server/test/src/services/correction/fix/replace_final_with_var_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,23 @@ void f() {
7575
await assertNoFix();
7676
}
7777

78+
Future<void> test_if_case_pattern() async {
79+
await resolveTestCode(r'''
80+
f() {
81+
if (0 case final a){
82+
print(a);
83+
}
84+
}
85+
''');
86+
await assertHasFix(r'''
87+
f() {
88+
if (0 case var a){
89+
print(a);
90+
}
91+
}
92+
''');
93+
}
94+
7895
/// https://github.com/dart-lang/sdk/issues/51864
7996
Future<void> test_listPattern_assignment() async {
8097
await resolveTestCode('''

0 commit comments

Comments
 (0)