Skip to content

Commit 767692b

Browse files
committed
[cfe] Remove error/warning on duplicate library name in export/import
Closes #42700 Change-Id: I1fd047ea91de45be727690cf6053298cecf91410 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/155326 Reviewed-by: Jens Johansen <[email protected]>
1 parent 07aa9ec commit 767692b

13 files changed

+115
-197
lines changed

pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,95 +2307,6 @@ Message _withArgumentsDuplicatedImportInType(String name, Uri uri_, Uri uri2_) {
23072307
arguments: {'name': name, 'uri': uri_, 'uri2': uri2_});
23082308
}
23092309

2310-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
2311-
const Template<Message Function(String name)> templateDuplicatedLibraryExport =
2312-
const Template<Message Function(String name)>(
2313-
messageTemplate:
2314-
r"""A library with name '#name' is exported more than once.""",
2315-
withArguments: _withArgumentsDuplicatedLibraryExport);
2316-
2317-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
2318-
const Code<Message Function(String name)> codeDuplicatedLibraryExport =
2319-
const Code<Message Function(String name)>(
2320-
"DuplicatedLibraryExport", templateDuplicatedLibraryExport,
2321-
analyzerCodes: <String>["EXPORT_DUPLICATED_LIBRARY_NAMED"]);
2322-
2323-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
2324-
Message _withArgumentsDuplicatedLibraryExport(String name) {
2325-
if (name.isEmpty) throw 'No name provided';
2326-
name = demangleMixinApplicationName(name);
2327-
return new Message(codeDuplicatedLibraryExport,
2328-
message: """A library with name '${name}' is exported more than once.""",
2329-
arguments: {'name': name});
2330-
}
2331-
2332-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
2333-
const Template<Message Function(String name)>
2334-
templateDuplicatedLibraryExportContext =
2335-
const Template<Message Function(String name)>(
2336-
messageTemplate: r"""'#name' is also exported here.""",
2337-
withArguments: _withArgumentsDuplicatedLibraryExportContext);
2338-
2339-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
2340-
const Code<Message Function(String name)> codeDuplicatedLibraryExportContext =
2341-
const Code<Message Function(String name)>("DuplicatedLibraryExportContext",
2342-
templateDuplicatedLibraryExportContext,
2343-
severity: Severity.context);
2344-
2345-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
2346-
Message _withArgumentsDuplicatedLibraryExportContext(String name) {
2347-
if (name.isEmpty) throw 'No name provided';
2348-
name = demangleMixinApplicationName(name);
2349-
return new Message(codeDuplicatedLibraryExportContext,
2350-
message: """'${name}' is also exported here.""",
2351-
arguments: {'name': name});
2352-
}
2353-
2354-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
2355-
const Template<Message Function(String name)> templateDuplicatedLibraryImport =
2356-
const Template<Message Function(String name)>(
2357-
messageTemplate:
2358-
r"""A library with name '#name' is imported more than once.""",
2359-
withArguments: _withArgumentsDuplicatedLibraryImport);
2360-
2361-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
2362-
const Code<Message Function(String name)> codeDuplicatedLibraryImport =
2363-
const Code<Message Function(String name)>(
2364-
"DuplicatedLibraryImport", templateDuplicatedLibraryImport,
2365-
analyzerCodes: <String>["IMPORT_DUPLICATED_LIBRARY_NAMED"],
2366-
severity: Severity.warning);
2367-
2368-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
2369-
Message _withArgumentsDuplicatedLibraryImport(String name) {
2370-
if (name.isEmpty) throw 'No name provided';
2371-
name = demangleMixinApplicationName(name);
2372-
return new Message(codeDuplicatedLibraryImport,
2373-
message: """A library with name '${name}' is imported more than once.""",
2374-
arguments: {'name': name});
2375-
}
2376-
2377-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
2378-
const Template<Message Function(String name)>
2379-
templateDuplicatedLibraryImportContext =
2380-
const Template<Message Function(String name)>(
2381-
messageTemplate: r"""'#name' is also imported here.""",
2382-
withArguments: _withArgumentsDuplicatedLibraryImportContext);
2383-
2384-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
2385-
const Code<Message Function(String name)> codeDuplicatedLibraryImportContext =
2386-
const Code<Message Function(String name)>("DuplicatedLibraryImportContext",
2387-
templateDuplicatedLibraryImportContext,
2388-
severity: Severity.context);
2389-
2390-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
2391-
Message _withArgumentsDuplicatedLibraryImportContext(String name) {
2392-
if (name.isEmpty) throw 'No name provided';
2393-
name = demangleMixinApplicationName(name);
2394-
return new Message(codeDuplicatedLibraryImportContext,
2395-
message: """'${name}' is also imported here.""",
2396-
arguments: {'name': name});
2397-
}
2398-
23992310
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
24002311
const Template<Message Function(Token token)> templateDuplicatedModifier =
24012312
const Template<Message Function(Token token)>(

pkg/front_end/lib/src/fasta/source/source_loader.dart

Lines changed: 1 addition & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,8 @@ import '../builder/type_declaration_builder.dart';
8181

8282
import '../export.dart' show Export;
8383

84-
import '../import.dart' show Import;
85-
8684
import '../fasta_codes.dart'
8785
show
88-
LocatedMessage,
8986
Message,
9087
SummaryTemplate,
9188
Template,
@@ -100,10 +97,6 @@ import '../fasta_codes.dart'
10097
templateAmbiguousSupertypes,
10198
templateCantReadFile,
10299
templateCyclicClassHierarchy,
103-
templateDuplicatedLibraryExport,
104-
templateDuplicatedLibraryExportContext,
105-
templateDuplicatedLibraryImport,
106-
templateDuplicatedLibraryImportContext,
107100
templateExtendingEnum,
108101
templateExtendingRestricted,
109102
templateIllegalMixin,
@@ -916,82 +909,7 @@ class SourceLoader extends Loader {
916909

917910
List<SourceClassBuilder> checkSemantics(ClassBuilder objectClass) {
918911
checkObjectClassHierarchy(objectClass);
919-
List<SourceClassBuilder> classes = handleHierarchyCycles(objectClass);
920-
921-
// Check imports and exports for duplicate names.
922-
// This is rather silly, e.g. it makes importing 'foo' and exporting another
923-
// 'foo' ok.
924-
builders.forEach((Uri uri, LibraryBuilder library) {
925-
if (library is SourceLibraryBuilder && library.loader == this) {
926-
// Check exports.
927-
if (library.exports.isNotEmpty) {
928-
Map<String, List<Export>> nameToExports;
929-
bool errorExports = false;
930-
for (Export export in library.exports) {
931-
String name = export.exported?.name ?? '';
932-
if (name != '') {
933-
nameToExports ??= new Map<String, List<Export>>();
934-
List<Export> exports = nameToExports[name] ??= <Export>[];
935-
exports.add(export);
936-
if (exports[0].exported != export.exported) errorExports = true;
937-
}
938-
}
939-
if (errorExports) {
940-
for (String name in nameToExports.keys) {
941-
List<Export> exports = nameToExports[name];
942-
if (exports.length < 2) continue;
943-
List<LocatedMessage> context = <LocatedMessage>[];
944-
for (Export export in exports.skip(1)) {
945-
context.add(templateDuplicatedLibraryExportContext
946-
.withArguments(name)
947-
.withLocation(uri, export.charOffset, noLength));
948-
}
949-
library.addProblem(
950-
templateDuplicatedLibraryExport.withArguments(name),
951-
exports[0].charOffset,
952-
noLength,
953-
uri,
954-
context: context);
955-
}
956-
}
957-
}
958-
959-
// Check imports.
960-
if (library.imports.isNotEmpty) {
961-
Map<String, List<Import>> nameToImports;
962-
bool errorImports;
963-
for (Import import in library.imports) {
964-
String name = import.imported?.name ?? '';
965-
if (name != '') {
966-
nameToImports ??= new Map<String, List<Import>>();
967-
List<Import> imports = nameToImports[name] ??= <Import>[];
968-
imports.add(import);
969-
if (imports[0].imported != import.imported) errorImports = true;
970-
}
971-
}
972-
if (errorImports != null) {
973-
for (String name in nameToImports.keys) {
974-
List<Import> imports = nameToImports[name];
975-
if (imports.length < 2) continue;
976-
List<LocatedMessage> context = <LocatedMessage>[];
977-
for (Import import in imports.skip(1)) {
978-
context.add(templateDuplicatedLibraryImportContext
979-
.withArguments(name)
980-
.withLocation(uri, import.charOffset, noLength));
981-
}
982-
library.addProblem(
983-
templateDuplicatedLibraryImport.withArguments(name),
984-
imports[0].charOffset,
985-
noLength,
986-
uri,
987-
context: context);
988-
}
989-
}
990-
}
991-
}
992-
});
993-
ticker.logMs("Checked imports and exports for duplicate names");
994-
return classes;
912+
return handleHierarchyCycles(objectClass);
995913
}
996914

997915
void buildComponent() {

pkg/front_end/messages.yaml

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,38 +1902,13 @@ DuplicatedExport:
19021902
lib2.dart: "class A {}"
19031903
main.dart: "export 'lib1.dart'; export 'lib2.dart';"
19041904

1905-
DuplicatedLibraryExport:
1906-
template: "A library with name '#name' is exported more than once."
1907-
analyzerCode: EXPORT_DUPLICATED_LIBRARY_NAMED
1908-
script:
1909-
lib1.dart: "library foo;"
1910-
lib2.dart: "library foo;"
1911-
main.dart: "export 'lib1.dart'; export 'lib2.dart';"
1912-
1913-
DuplicatedLibraryExportContext:
1914-
template: "'#name' is also exported here."
1915-
severity: CONTEXT
1916-
19171905
DuplicatedExportInType:
19181906
template: "'#name' is exported from both '#uri' and '#uri2'."
19191907

19201908
DuplicatedImport:
19211909
template: "'#name' is imported from both '#uri' and '#uri2'."
19221910
severity: IGNORED
19231911

1924-
DuplicatedLibraryImport:
1925-
template: "A library with name '#name' is imported more than once."
1926-
severity: WARNING
1927-
analyzerCode: IMPORT_DUPLICATED_LIBRARY_NAMED
1928-
script:
1929-
lib1.dart: "library foo;"
1930-
lib2.dart: "library foo;"
1931-
main.dart: "import 'lib1.dart'; import 'lib2.dart';"
1932-
1933-
DuplicatedLibraryImportContext:
1934-
template: "'#name' is also imported here."
1935-
severity: CONTEXT
1936-
19371912
DuplicatedImportInType:
19381913
template: "'#name' is imported from both '#uri' and '#uri2'."
19391914
analyzerCode: AMBIGUOUS_IMPORT
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'duplicate_import_lib1.dart';
6+
import 'duplicate_import_lib2.dart';
7+
8+
export 'duplicate_import_lib1.dart';
9+
export 'duplicate_import_lib2.dart';
10+
11+
main() {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
4+
import "org-dartlang-testcase:///duplicate_import_lib1.dart";
5+
import "org-dartlang-testcase:///duplicate_import_lib2.dart";
6+
export "org-dartlang-testcase:///duplicate_import_lib1.dart";
7+
export "org-dartlang-testcase:///duplicate_import_lib2.dart";
8+
9+
static method main() → dynamic
10+
;
11+
12+
library foo /*isNonNullableByDefault*/;
13+
import self as self2;
14+
15+
16+
library foo /*isNonNullableByDefault*/;
17+
import self as self3;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
4+
import "org-dartlang-testcase:///duplicate_import_lib1.dart";
5+
import "org-dartlang-testcase:///duplicate_import_lib2.dart";
6+
export "org-dartlang-testcase:///duplicate_import_lib1.dart";
7+
export "org-dartlang-testcase:///duplicate_import_lib2.dart";
8+
9+
static method main() → dynamic {}
10+
11+
library foo /*isNonNullableByDefault*/;
12+
import self as self2;
13+
14+
15+
library foo /*isNonNullableByDefault*/;
16+
import self as self3;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
4+
import "org-dartlang-testcase:///duplicate_import_lib1.dart";
5+
import "org-dartlang-testcase:///duplicate_import_lib2.dart";
6+
export "org-dartlang-testcase:///duplicate_import_lib1.dart";
7+
export "org-dartlang-testcase:///duplicate_import_lib2.dart";
8+
9+
static method main() → dynamic {}
10+
11+
library foo /*isNonNullableByDefault*/;
12+
import self as self2;
13+
14+
15+
library foo /*isNonNullableByDefault*/;
16+
import self as self3;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import 'duplicate_import_lib1.dart';
2+
import 'duplicate_import_lib2.dart';
3+
export 'duplicate_import_lib1.dart';
4+
export 'duplicate_import_lib2.dart';
5+
6+
main() {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import 'duplicate_import_lib1.dart';
2+
import 'duplicate_import_lib2.dart';
3+
export 'duplicate_import_lib1.dart';
4+
export 'duplicate_import_lib2.dart';
5+
6+
main() {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
4+
import "org-dartlang-testcase:///duplicate_import_lib1.dart";
5+
import "org-dartlang-testcase:///duplicate_import_lib2.dart";
6+
export "org-dartlang-testcase:///duplicate_import_lib1.dart";
7+
export "org-dartlang-testcase:///duplicate_import_lib2.dart";
8+
9+
static method main() → dynamic {}
10+
11+
library foo /*isNonNullableByDefault*/;
12+
import self as self2;
13+
14+
15+
library foo /*isNonNullableByDefault*/;
16+
import self as self3;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
4+
import "org-dartlang-testcase:///duplicate_import_lib1.dart";
5+
import "org-dartlang-testcase:///duplicate_import_lib2.dart";
6+
export "org-dartlang-testcase:///duplicate_import_lib1.dart";
7+
export "org-dartlang-testcase:///duplicate_import_lib2.dart";
8+
9+
static method main() → dynamic {}
10+
11+
library foo /*isNonNullableByDefault*/;
12+
import self as self2;
13+
14+
15+
library foo /*isNonNullableByDefault*/;
16+
import self as self3;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
library foo;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
library foo;

0 commit comments

Comments
 (0)