Skip to content

Commit 490b0f1

Browse files
FMorschelCommit Queue
authored and
Commit Queue
committed
[DAS] Ambiguous Import fix - fix for static members
Fixes: #60276 Change-Id: I8f5cdda4b2e8acfd644c35b3fe54dfab67b8e081 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414360 Reviewed-by: Samuel Rawlins <[email protected]> Auto-Submit: Felipe Morschel <[email protected]> Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent bc9def5 commit 490b0f1

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ class AmbiguousImportFix extends MultiCorrectionProducer {
2828
prefix = node.importPrefix?.name.lexeme;
2929
} else if (node is SimpleIdentifier) {
3030
element = node.element;
31-
if (node.parent case PrefixedIdentifier(prefix: var currentPrefix)) {
31+
if (node.parent case PrefixedIdentifier(
32+
prefix: var currentPrefix,
33+
) when currentPrefix != node) {
3234
prefix = currentPrefix.name;
3335
}
3436
}

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

+56
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,62 @@ void f(l.N? n) {
539539
''', matchFixMessage: "Hide others to use 'N' from 'lib1.dart' as l");
540540
}
541541

542+
Future<void> test_static_member() async {
543+
newFile(join(testPackageLibPath, 'lib1.dart'), '''
544+
class N {}''');
545+
newFile(join(testPackageLibPath, 'lib2.dart'), '''
546+
class N {}''');
547+
await resolveTestCode('''
548+
import 'lib1.dart';
549+
import 'lib2.dart';
550+
551+
void f() {
552+
var _ = [N.new];
553+
}
554+
''');
555+
await assertHasFix(
556+
'''
557+
import 'lib1.dart' hide N;
558+
import 'lib2.dart';
559+
560+
void f() {
561+
var _ = [N.new];
562+
}
563+
''',
564+
matchFixMessage: "Hide others to use 'N' from 'lib2.dart'",
565+
errorFilter:
566+
(error) => error.errorCode == CompileTimeErrorCode.AMBIGUOUS_IMPORT,
567+
);
568+
}
569+
570+
Future<void> test_static_member_prefixed() async {
571+
newFile(join(testPackageLibPath, 'lib1.dart'), '''
572+
class N {}''');
573+
newFile(join(testPackageLibPath, 'lib2.dart'), '''
574+
class N {}''');
575+
await resolveTestCode('''
576+
import 'lib1.dart' as l;
577+
import 'lib2.dart' as l;
578+
579+
void f() {
580+
var _ = [l.N.new];
581+
}
582+
''');
583+
await assertHasFix(
584+
'''
585+
import 'lib1.dart' as l hide N;
586+
import 'lib2.dart' as l;
587+
588+
void f() {
589+
var _ = [l.N.new];
590+
}
591+
''',
592+
matchFixMessage: "Hide others to use 'N' from 'lib2.dart' as l",
593+
errorFilter:
594+
(error) => error.errorCode == CompileTimeErrorCode.AMBIGUOUS_IMPORT,
595+
);
596+
}
597+
542598
Future<void> test_triple() async {
543599
newFile(join(testPackageLibPath, 'lib1.dart'), '''
544600
export 'lib3.dart';''');

0 commit comments

Comments
 (0)