Skip to content

Commit 47f4ff2

Browse files
AgamAgarwalCommit Queue
authored andcommitted
Handle TopLevelVariableDeclaration in ConvertToFunctionDeclaration.
Closes #61819 GitOrigin-RevId: 6113f84 Change-Id: I33d684af2ce9dd050679235c5bd2182fed1f1dfe Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457560 Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent b668fc8 commit 47f4ff2

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class ConvertToFunctionDeclaration extends ResolvedCorrectionProducer {
4848
grandParentSemicolon = grandParent.semicolon;
4949
} else if (grandParent is FieldDeclaration) {
5050
grandParentSemicolon = grandParent.semicolon;
51+
} else if (grandParent is TopLevelVariableDeclaration) {
52+
grandParentSemicolon = grandParent.semicolon;
5153
} else {
5254
return;
5355
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,23 @@ void f() {
270270
''');
271271
}
272272

273+
Future<void> test_top_level_declaration() async {
274+
await resolveTestCode('''
275+
final v1 = () => 42;
276+
277+
void f() {
278+
v1();
279+
}
280+
''');
281+
await assertHasFix('''
282+
int v1() => 42;
283+
284+
void f() {
285+
v1();
286+
}
287+
''');
288+
}
289+
273290
Future<void> test_type() async {
274291
await resolveTestCode('''
275292
void f() {

0 commit comments

Comments
 (0)