diff --git a/pkg/analysis_server/lib/src/services/correction/dart/ambiguous_import_fix.dart b/pkg/analysis_server/lib/src/services/correction/dart/ambiguous_import_fix.dart index 7fbf3ba1555a..faa4b0f885b6 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/ambiguous_import_fix.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/ambiguous_import_fix.dart @@ -48,6 +48,11 @@ class AmbiguousImportFix extends MultiCorrectionProducer { prefix, ); + // If we have multiple imports of the same library, then we won't fix it. + if (uris.length != uris.toSet().length) { + return const []; + } + if (unit == null || importDirectives.isEmpty || uris.isEmpty) { return const []; } @@ -161,9 +166,8 @@ class _ImportAddHide extends ResolvedCorrectionProducer { @override CorrectionApplicability get applicability => - // TODO(applicability): comment on why. - CorrectionApplicability - .singleLocation; + // TODO(applicability): comment on why. + CorrectionApplicability.singleLocation; @override List get fixArguments { @@ -235,9 +239,8 @@ class _ImportRemoveShow extends ResolvedCorrectionProducer { @override CorrectionApplicability get applicability => - // TODO(applicability): comment on why. - CorrectionApplicability - .singleLocation; + // TODO(applicability): comment on why. + CorrectionApplicability.singleLocation; @override List get fixArguments { diff --git a/pkg/analysis_server/test/src/services/correction/fix/ambiguous_import_fix_test.dart b/pkg/analysis_server/test/src/services/correction/fix/ambiguous_import_fix_test.dart index 8673b187c6bf..c2b57143b792 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/ambiguous_import_fix_test.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/ambiguous_import_fix_test.dart @@ -150,6 +150,29 @@ class C with M {} ); } + Future test_double_equal_importUris() async { + // https://github.com/dart-lang/sdk/issues/56830#issuecomment-2573945155 + newFile(join(testPackageLibPath, 'lib1.dart'), ''' +var foo = 0; +var bar = 0; +var baz = 0; +'''); + newFile(join(testPackageLibPath, 'lib2.dart'), ''' +var foo = 0;'''); + await resolveTestCode(''' +import 'lib1.dart' hide bar; +import 'lib1.dart' hide baz; +import 'lib2.dart'; + +void f() { + print(bar); + print(baz); + print(foo); +} +'''); + await assertNoFix(); + } + Future test_double_exportedByImport() async { newFile(join(testPackageLibPath, 'lib1.dart'), ''' mixin M {}'''); @@ -663,6 +686,29 @@ void f(l.N? n) { ''', matchFixMessage: "Remove show to use 'N' from 'lib1.dart' as l"); } + Future test_double_equal_importUris() async { + // https://github.com/dart-lang/sdk/issues/56830#issuecomment-2573945155 + newFile(join(testPackageLibPath, 'lib1.dart'), ''' +var foo = 0; +var bar = 0; +var baz = 0; +'''); + newFile(join(testPackageLibPath, 'lib2.dart'), ''' +var foo = 0;'''); + await resolveTestCode(''' +import 'lib1.dart' show bar, foo; +import 'lib1.dart' show baz, foo; +import 'lib2.dart'; + +void f() { + print(bar); + print(baz); + print(foo); +} +'''); + await assertNoFix(); + } + Future test_double_oneHide() async { newFile(join(testPackageLibPath, 'lib1.dart'), ''' const foo = 0;''');