Skip to content

Commit e4de6ab

Browse files
FMorschelCommit Queue
authored andcommitted
[DAS] Adds Remove const fix to const_eval_method_invocation
Fixes: #61450 Change-Id: I6fcc6148ae6a550ce3c006d1d26f8ca18786e0fa Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448600 Reviewed-by: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Auto-Submit: Felipe Morschel <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent ce9c2d3 commit e4de6ab

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ CompileTimeErrorCode.CONST_EVAL_EXTENSION_TYPE_METHOD:
435435
CompileTimeErrorCode.CONST_EVAL_FOR_ELEMENT:
436436
status: needsEvaluation
437437
CompileTimeErrorCode.CONST_EVAL_METHOD_INVOCATION:
438-
status: needsEvaluation
438+
status: hasFix
439439
CompileTimeErrorCode.CONST_EVAL_PRIMITIVE_EQUALITY:
440440
status: needsEvaluation
441441
CompileTimeErrorCode.CONST_EVAL_PROPERTY_ACCESS:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ final _builtInNonLintGenerators = <DiagnosticCode, List<ProducerGenerator>>{
594594
CreateNoSuchMethod.new,
595595
MakeClassAbstract.new,
596596
],
597+
CompileTimeErrorCode.constEvalMethodInvocation: [RemoveConst.new],
597598
CompileTimeErrorCode.constInitializedWithNonConstantValue: [
598599
RemoveConst.new,
599600
RemoveNew.new,

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,43 @@ class RemoveConstConstConstructorParamTypeMismatchTest
2727
@override
2828
FixKind get kind => DartFixKind.REMOVE_CONST;
2929

30+
Future<void> test_methodInvocation() async {
31+
await resolveTestCode(r'''
32+
class A {
33+
const A([int _ = 0]);
34+
35+
int myMethod() => 0;
36+
}
37+
38+
void foo(A a) {
39+
const _ = A(a.myMethod());
40+
}
41+
''');
42+
await assertHasFix(r'''
43+
class A {
44+
const A([int _ = 0]);
45+
46+
int myMethod() => 0;
47+
}
48+
49+
void foo(A a) {
50+
final _ = A(a.myMethod());
51+
}
52+
''');
53+
}
54+
55+
Future<void> test_methodInvocation_enum() async {
56+
await resolveTestCode(r'''
57+
enum E {
58+
enumValue(["text"].map((x) => x));
59+
60+
const E(this.strings);
61+
final Iterable<String> strings;
62+
}
63+
''');
64+
await assertNoFix();
65+
}
66+
3067
Future<void> test_named() async {
3168
await resolveTestCode(r'''
3269
class A {

0 commit comments

Comments
 (0)