dart-lang / dart-lang/language

Clarify specification of errors around exports of clashing names

Open
#504 8 comments 0 reactions 0 assignees View on GitHub
specification
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

The specification says (section 18.2):

"For each entry mapping key k to declaration d in NSn an entry mapping
k to d is added to the exported namespace of L unless a top-level declaration
with the name k exists in L."

This seems to imply that if the name `k` is declared in `L`, then no other declarations named by `k` are added to the export scope.

The specification also says that:

"It is a compile-time error if a name N is re-exported by a library L and N
is introduced into the export namespace of L by more than one export, unless
all exports refer to same declaration for the name N. "

It is not entirely clear to me what behavior is intended by the second clause when the first applies.

The analyzer seems to take the interpretation that the second clause is intended to apply, and hence that an error should be issued.

The CFE seems to take the interpretation that the second clause does not apply (presumably because "added to" and "introduced into" are interpreted as being the same concept).

Which interpretation is correct? The CFE interpretation seems more consistent to me. Either way we should clarify this to make it completely clear, and we should make the implementations consistent.

Test case:

test3.dart
```dart
int x = 3;
```

test4.dart
```dart
int x = 4;
```

test2.dart
```dart
export "test3.dart";
export "test4.dart";

int x = 2;
```

test1.dart
```dart
export "test3.dart";
export "test4.dart";
```

```
leafp-macbookpro:sdk leafp$ ~/src/dart-repo/sdk/xcodebuild/ReleaseX64/dart-sdk/bin/dartanalyzer ~/tmp/test2.dart
Analyzing /Users/leafp/tmp/test2.dart...
error • The name 'x=' is defined in the libraries 'file:///Users/leafp/tmp/test3.dart' and 'file:///Users/leafp/tmp/test4.dart' at /Users/leafp/tmp/test2.dart:6:1 • ambiguous_export
1 error found.
leafp-macbookpro:sdk leafp$ ~/src/dart-repo/sdk/xcodebuild/ReleaseX64/dart-sdk/bin/dart ~/tmp/test2.dart
Dart_LoadScriptFromKernel: The binary program does not contain 'main'.
```

```
leafp-macbookpro:sdk leafp$ ~/src/dart-repo/sdk/xcodebuild/ReleaseX64/dart-sdk/bin/dartanalyzer ~/tmp/test1.dart
Analyzing /Users/leafp/tmp/test1.dart...
error • The name 'x=' is defined in the libraries 'file:///Users/leafp/tmp/test3.dart' and 'file:///Users/leafp/tmp/test4.dart' at /Users/leafp/tmp/test1.dart:6:1 • ambiguous_export
1 error found.
leafp-macbookpro:sdk leafp$ ~/src/dart-repo/sdk/xcodebuild/ReleaseX64/dart-sdk/bin/dart ~/tmp/test1.dart
../../../tmp/test1.dart:6:1: Error: 'x' is exported from both '../../../tmp/test3.dart' and '../../../tmp/test4.dart'.
export "test4.dart";
^
```

cc @bwilkerson @lrhn @eernstg @munificent

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.