Skip to content

Commit

Permalink
removes fix when multiple equal uri
Browse files Browse the repository at this point in the history
  • Loading branch information
FMorschel committed Jan 6, 2025
1 parent 8f1adaf commit c93d33b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
Expand Down Expand Up @@ -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<String> get fixArguments {
Expand Down Expand Up @@ -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<String> get fixArguments {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,29 @@ class C with M {}
);
}

Future<void> 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<void> test_double_exportedByImport() async {
newFile(join(testPackageLibPath, 'lib1.dart'), '''
mixin M {}''');
Expand Down Expand Up @@ -663,6 +686,29 @@ void f(l.N? n) {
''', matchFixMessage: "Remove show to use 'N' from 'lib1.dart' as l");
}

Future<void> 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<void> test_double_oneHide() async {
newFile(join(testPackageLibPath, 'lib1.dart'), '''
const foo = 0;''');
Expand Down

0 comments on commit c93d33b

Please sign in to comment.