dart-lang / dart-lang/language
Dart uses raw URIs for library identity.
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
Dart currently identifies libraries by their import URI.
That causes troubles in some situations:
* Different case on Windows (https://github.com/dart-lang/sdk/issues/28895)
* Starting programs using `dart lib/main.dart` (https://github.com/dart-lang/sdk/issues/37978)
I suggest that we loosen the language specification to the point where the compiler is in charge of detecting when two URIs represent the same library, and it is allowed to *canonicalize* the URI of the library prior to resolving imports.
If the compiler can recognize that the underlying file system is case insensitive, then it is free (and encouraged) to consider `Foo.dart` and `foo.dart` the same library. It might still want to give a warning/hint that the code won't work on case-sensitive platforms.
If someone runs or imports `lib/main.dart`, the compiler is free to rewrite that to `package:currentPackage/main.dart`. We already do that for entry points (see also https://github.com/dart-lang/sdk/issues/37978), but it sometimes fails for direct imports from the `bin/` directory or other cases.
In general, allow the compiler to recognize that two URIs are actually referring the same library *file* using any available information, not just what the language specification can predict.
It still have to be in *some* way predictable. Generally, if it's the same underlying file, then it should be the same library.
Contributor guide
Research direction
Start by reading the language specification rules for library identity and import URI resolution, then review the linked issues about case differences and direct dart lib/main.dart execution. Done would require a predictable specification change that lets the compiler recognize equivalent library files and covers package, case-insensitive, and direct-entry-point cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100