Skip to content

Commit 6eef2c0

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committed
Add fix for NON_FINAL_FIELD_IN_ENUM
Change-Id: I4eb8125468290af44b65343d620ee2646c2594c8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/270800 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 50aae78 commit 6eef2c0

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,8 @@ CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY:
791791
CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT:
792792
status: needsEvaluation
793793
CompileTimeErrorCode.NON_FINAL_FIELD_IN_ENUM:
794-
status: needsFix
795-
notes: Use MakeFinal.new
794+
status: hasFix
795+
since: 2.17
796796
CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR:
797797
status: needsEvaluation
798798
CompileTimeErrorCode.NON_GENERATIVE_IMPLICIT_CONSTRUCTOR:

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,9 @@ class FixProcessor extends BaseProcessor {
10821082
CompileTimeErrorCode.NON_CONST_GENERATIVE_ENUM_CONSTRUCTOR: [
10831083
AddConst.new,
10841084
],
1085+
CompileTimeErrorCode.NON_FINAL_FIELD_IN_ENUM: [
1086+
MakeFinal.new,
1087+
],
10851088
CompileTimeErrorCode.NON_TYPE_AS_TYPE_ARGUMENT: [
10861089
CreateClass.new,
10871090
CreateMixin.new,

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'fix_processor.dart';
1111

1212
void main() {
1313
defineReflectiveSuite(() {
14+
defineReflectiveTests(NonFinalFieldInEnumTest);
1415
defineReflectiveTests(PreferFinalFieldsBulkTest);
1516
defineReflectiveTests(PreferFinalFieldsTest);
1617
defineReflectiveTests(PreferFinalFieldsWithNullSafetyTest);
@@ -21,6 +22,42 @@ void main() {
2122
});
2223
}
2324

25+
@reflectiveTest
26+
class NonFinalFieldInEnumTest extends FixProcessorTest {
27+
@override
28+
FixKind get kind => DartFixKind.MAKE_FINAL;
29+
30+
Future<void> test_field_type() async {
31+
await resolveTestCode('''
32+
enum E {
33+
one, two;
34+
int f = 2;
35+
}
36+
''');
37+
await assertHasFix('''
38+
enum E {
39+
one, two;
40+
final int f = 2;
41+
}
42+
''');
43+
}
44+
45+
Future<void> test_field_var() async {
46+
await resolveTestCode('''
47+
enum E {
48+
one, two;
49+
var f = 2;
50+
}
51+
''');
52+
await assertHasFix('''
53+
enum E {
54+
one, two;
55+
final f = 2;
56+
}
57+
''');
58+
}
59+
}
60+
2461
@reflectiveTest
2562
class PreferFinalFieldsBulkTest extends BulkFixProcessorTest {
2663
@override

0 commit comments

Comments
 (0)