Skip to content

Commit 63d6e6f

Browse files
pqCommit Queue
authored and
Commit Queue
committed
quick fix for NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR_USING_NEW
See: #55917 Change-Id: I9576105618d0201b4fdc339361b6c164870267b9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370140 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Phil Quitslund <[email protected]> Auto-Submit: Phil Quitslund <[email protected]>
1 parent a1b42e1 commit 63d6e6f

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3638,9 +3638,7 @@ WarningCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR:
36383638
notes: |-
36393639
The fix is to add `const` before the constructor invocation.
36403640
WarningCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR_USING_NEW:
3641-
status: needsFix
3642-
notes: |-
3643-
The fix is to replace `new` with `const`.
3641+
status: hasFix
36443642
WarningCode.NON_NULLABLE_EQUALS_PARAMETER:
36453643
status: needsFix
36463644
notes: |-

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,9 @@ final _builtInNonLintProducers = <ErrorCode, List<ProducerGenerator>>{
15821582
WarningCode.MUST_CALL_SUPER: [
15831583
AddCallSuper.new,
15841584
],
1585+
WarningCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR_USING_NEW: [
1586+
ReplaceNewWithConst.new,
1587+
],
15851588
WarningCode.NULLABLE_TYPE_IN_CATCH_CLAUSE: [
15861589
RemoveQuestionMark.new,
15871590
],

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ class ReplaceNewWithConstTest extends FixProcessorLintTest {
103103
@override
104104
String get lintCode => LintNames.prefer_const_constructors;
105105

106+
@override
107+
void setUp() {
108+
super.setUp();
109+
writeTestPackageConfig(meta: true);
110+
}
111+
106112
Future<void> test_new() async {
107113
await resolveTestCode('''
108114
class C {
@@ -137,4 +143,23 @@ void f() {
137143
// handled by ADD_CONST
138144
await assertNoFix();
139145
}
146+
147+
Future<void> test_nonConstCallToLiteralConstructorUsingNew() async {
148+
await resolveTestCode('''
149+
import 'package:meta/meta.dart';
150+
class A {
151+
@literal
152+
const A();
153+
}
154+
var a = new A();
155+
''');
156+
await assertHasFix('''
157+
import 'package:meta/meta.dart';
158+
class A {
159+
@literal
160+
const A();
161+
}
162+
var a = const A();
163+
''');
164+
}
140165
}

0 commit comments

Comments
 (0)