Skip to content

Commit 4fbb4dc

Browse files
bwilkersonCommit Queue
authored andcommitted
Fix the field formal parameter to normal parameter assist
This disables the assist if the field formal parameter happens to also be an older style function typed parameter. As written the assist produces invalid code, and the older style is strongly discouraged so not supporting it shouldn't impact very many users. Change-Id: I44a3942b4656265bb1cbbba29e68fff61962b689 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433260 Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent ef4e39a commit 4fbb4dc

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ constraint][language version] lower bound to 3.9 or greater (`sdk: '^3.9.0'`).
1818

1919
- Add the [`switch_on_type`][] lint rule.
2020
- Add the [`unnecessary_unawaited`][] lint rule.
21+
- Add an assist to convert a field formal parameter to a normal parameter.
2122

2223
[`switch_on_type`]: http://dart.dev/lints/switch_on_type
2324
[`unnecessary_unawaited`]: http://dart.dev/lints/unnecessary_unawaited

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ConvertFieldFormalToNormal extends ResolvedCorrectionProducer {
2323
@override
2424
Future<void> compute(ChangeBuilder builder) async {
2525
var parameter = node;
26-
if (parameter is! FieldFormalParameter) {
26+
if (parameter is! FieldFormalParameter || parameter.parameters != null) {
2727
return;
2828
}
2929
var field = parameter.declaredFragment?.element.field2;

pkg/analysis_server/test/src/services/correction/assist/convert_field_formal_to_normal_test.dart

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,19 +281,30 @@ class C {
281281
''');
282282
}
283283

284-
Future<void> test_withFunctionTypedField() async {
284+
Future<void> test_withFunctionTypedField_functionTypedParameter() async {
285285
await resolveTestCode('''
286286
class C {
287287
void Function() f;
288288
289289
C({required this.f^()});
290290
}
291+
''');
292+
await assertNoAssist();
293+
}
294+
295+
Future<void> test_withFunctionTypedField_normalParameter() async {
296+
await resolveTestCode('''
297+
class C {
298+
void Function() f;
299+
300+
C({required this.f^});
301+
}
291302
''');
292303
await assertHasAssist('''
293304
class C {
294305
void Function() f;
295306
296-
C({required void Function() f()}) : f = f;
307+
C({required void Function() f}) : f = f;
297308
}
298309
''');
299310
}

0 commit comments

Comments
 (0)