diff --git a/CHANGELOG.md b/CHANGELOG.md index f16430f2e22..f03681d1cc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ constraint][language version] lower bound to 3.9 or greater (`sdk: '^3.9.0'`). - Add the [`switch_on_type`][] lint rule. - Add the [`unnecessary_unawaited`][] lint rule. +- Add an assist to convert a field formal parameter to a normal parameter. [`switch_on_type`]: http://dart.dev/lints/switch_on_type [`unnecessary_unawaited`]: http://dart.dev/lints/unnecessary_unawaited diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_field_formal_to_normal.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_field_formal_to_normal.dart index fb434a3aa03..f437ba737d2 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/convert_field_formal_to_normal.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_field_formal_to_normal.dart @@ -23,7 +23,7 @@ class ConvertFieldFormalToNormal extends ResolvedCorrectionProducer { @override Future compute(ChangeBuilder builder) async { var parameter = node; - if (parameter is! FieldFormalParameter) { + if (parameter is! FieldFormalParameter || parameter.parameters != null) { return; } var field = parameter.declaredFragment?.element.field2; diff --git a/pkg/analysis_server/test/src/services/correction/assist/convert_field_formal_to_normal_test.dart b/pkg/analysis_server/test/src/services/correction/assist/convert_field_formal_to_normal_test.dart index 7c3add339b5..785f820d0f6 100644 --- a/pkg/analysis_server/test/src/services/correction/assist/convert_field_formal_to_normal_test.dart +++ b/pkg/analysis_server/test/src/services/correction/assist/convert_field_formal_to_normal_test.dart @@ -281,19 +281,30 @@ class C { '''); } - Future test_withFunctionTypedField() async { + Future test_withFunctionTypedField_functionTypedParameter() async { await resolveTestCode(''' class C { void Function() f; C({required this.f^()}); } +'''); + await assertNoAssist(); + } + + Future test_withFunctionTypedField_normalParameter() async { + await resolveTestCode(''' +class C { + void Function() f; + + C({required this.f^}); +} '''); await assertHasAssist(''' class C { void Function() f; - C({required void Function() f()}) : f = f; + C({required void Function() f}) : f = f; } '''); }