Skip to content

Commit 3cc8940

Browse files
bwilkersonCommit Queue
authored andcommitted
Make inline-method not inline references in combinators
An earlier CL fixed a bug where an inline-method refactor could be initiated at a reference to a top-level function in an import combinator. This CL makes the corresponding change to prevent such references from being changed when the refactor is initiated at the declaration site. Change-Id: I769ff83ce946d971780474a9908e1ac63bd1e02d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434180 Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
1 parent 81e02ed commit 3cc8940

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

pkg/analysis_server/lib/src/services/refactoring/legacy/inline_method.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,11 @@ class _ReferenceProcessor {
702702
if (!_shouldProcess()) {
703703
return;
704704
}
705+
// References in a combinator list can't be inlined, but not doing so isn't
706+
// an error.
707+
if (nodeParent is Combinator) {
708+
return;
709+
}
705710
// If the element being inlined is async, ensure that the function
706711
// body that encloses the method is also async.
707712
if (ref._methodElement!.firstFragment.isAsynchronous) {

pkg/analysis_server/test/services/refactoring/legacy/inline_method_test.dart

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,32 @@ void f() {
243243
);
244244
}
245245

246-
Future<void> test_bad_inShowCombinator() async {
246+
Future<void> test_bad_inShowCombinator_atDeclaration() async {
247+
var referencingFilePath = '$testPackageLibPath/a.dart';
248+
newFile(referencingFilePath, '''
249+
import 'test.dart' show f;
250+
251+
void g() {
252+
f();
253+
}
254+
''');
255+
await indexTestUnit(r'''
256+
void f() {
257+
print(42);
258+
}
259+
''');
260+
_createRefactoring('f(');
261+
await _assertSuccessfulRefactoring('');
262+
assertFileChangeResult(referencingFilePath, '''
263+
import 'test.dart' show f;
264+
265+
void g() {
266+
print(42);
267+
}
268+
''');
269+
}
270+
271+
Future<void> test_bad_inShowCombinator_atShowCombinator() async {
247272
newFile('$testPackageLibPath/a.dart', '''
248273
void f() {
249274
print(42);

0 commit comments

Comments
 (0)