diff --git a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml index d556544c1228..4988b795cf03 100644 --- a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml +++ b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml @@ -3638,9 +3638,7 @@ WarningCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR: notes: |- The fix is to add `const` before the constructor invocation. WarningCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR_USING_NEW: - status: needsFix - notes: |- - The fix is to replace `new` with `const`. + status: hasFix WarningCode.NON_NULLABLE_EQUALS_PARAMETER: status: needsFix notes: |- diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart index 78f4b2c842cc..5402e0be2771 100644 --- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart +++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart @@ -1582,6 +1582,9 @@ final _builtInNonLintProducers = >{ WarningCode.MUST_CALL_SUPER: [ AddCallSuper.new, ], + WarningCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR_USING_NEW: [ + ReplaceNewWithConst.new, + ], WarningCode.NULLABLE_TYPE_IN_CATCH_CLAUSE: [ RemoveQuestionMark.new, ], diff --git a/pkg/analysis_server/test/src/services/correction/fix/replace_new_with_const_test.dart b/pkg/analysis_server/test/src/services/correction/fix/replace_new_with_const_test.dart index 8abaadbdf82f..ba91f0d66ebe 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/replace_new_with_const_test.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/replace_new_with_const_test.dart @@ -103,6 +103,12 @@ class ReplaceNewWithConstTest extends FixProcessorLintTest { @override String get lintCode => LintNames.prefer_const_constructors; + @override + void setUp() { + super.setUp(); + writeTestPackageConfig(meta: true); + } + Future test_new() async { await resolveTestCode(''' class C { @@ -137,4 +143,23 @@ void f() { // handled by ADD_CONST await assertNoFix(); } + + Future test_nonConstCallToLiteralConstructorUsingNew() async { + await resolveTestCode(''' +import 'package:meta/meta.dart'; +class A { + @literal + const A(); +} +var a = new A(); +'''); + await assertHasFix(''' +import 'package:meta/meta.dart'; +class A { + @literal + const A(); +} +var a = const A(); +'''); + } }