Skip to content

Commit

Permalink
Issue 53669: Remove duplicate await when inlining methods.
Browse files Browse the repository at this point in the history
Fixes #53669

Change-Id: I64eb73d5eef4a8a8ab5184b3e67bb2303faed5e7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/360580
Commit-Queue: Keerti Parthasarathy <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
  • Loading branch information
keertip authored and Commit Queue committed Apr 2, 2024
1 parent b2d31da commit 8dcb212
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:analysis_server/src/utilities/strings.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/precedence.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/source/source_range.dart';
Expand Down Expand Up @@ -572,6 +573,12 @@ class _ReferenceProcessor {
}
// do replace
var methodUsageRange = range.node(usage);
var awaitKeyword = Keyword.AWAIT.lexeme;
if (usage.parent is AwaitExpression &&
source.startsWith(awaitKeyword)) {
// remove the duplicate await keyword and the following whitespace.
source = source.substring(awaitKeyword.length + 1);
}
var edit = newSourceEdit_range(methodUsageRange, source);
_addRefEdit(edit);
} else {
Expand Down
16 changes: 16 additions & 0 deletions pkg/analysis_server/test/edit/refactoring_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,22 @@ void f() {
''');
}

Future<void> test_topLevelFunction_async() {
addTestFile('''
Future<int> a() async => 3;
Future<int> b() async => await a();
Future<int> c() async => await b();
}
''');
return assertSuccessfulRefactoring(() {
return _sendInlineRequest('b(');
}, '''
Future<int> a() async => 3;
Future<int> c() async => await a();
}
''');
}

Future<void> test_topLevelFunction_oneInvocation() {
addTestFile('''
test(a, b) {
Expand Down

0 comments on commit 8dcb212

Please sign in to comment.