-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Absolute imports fail when used in a package #6612
Comments
Justin, can you please try with "file:///Applications/dart/..." and report your experience? Added NeedsInfo label. |
It works with file:/// |
Thanks for verifying. This behaves as expected, since you are passing a relative URI to the import. cc @peter-ahe-google. |
Let me elaborate a bit on what absolute means in this context: an absolute file path is not an absolute URI, it is a relative URI because it does include a scheme. If you take a look at the specification, section 13.1 (Imports), you will see that the definition of "import" is: libraryImport: It also says that "An import specifies a URI x where the declaration of an imported library is to be found." and that "The interpretation of URIs is described in section 13.5 below.". This is from section 13.5 (URIs): "Otherwise, any relative URI is interpreted as relative to the the location of the current library." As I mentioned above, your (absolute) file path is a relative URI. So this part of the specification applies. Although the specification goes to great length to say that it doesn't refer to "IETF RFC 3986", it is actually referencing RFC 3986 when it says "...interpreted as relative to...", in particular: http://tools.ietf.org/html/rfc3986#section-5 The location of the current library (written as an absolute URI), in this case, is "package:test/lib.dart", not "file:///Users/justinfagnani/dart/test/bin/packages/test/lib.dart". See also issue #3148. |
FWIW, I think there is a bug in how the VM converts package-URIs to file-URIs. Notice this file path: /Users/justinfagnani/dart/test/bin/packages//Applications/dart/dart-sdk/lib/_internal/compiler/compiler.dart'package:test/lib.dart It is a bug that there are two slashes between "packages" and "Applications". This is most likely due to this line: path = "${_packageRoot}${uri.path}"; In _filePathFromPackageUri from dart/runtime/bin/builtin.dart. Instead, if uri.path starts with '/', it should be: path = "${_packageRoot}.${uri.path}"; |
An absolute import inside a package seems to be resolving to a path inside the packages folder. WIth the example below I get this error:
Unable to open file: /Users/justinfagnani/dart/test/bin/packages//Applications/dart/dart-sdk/lib/_internal/compiler/compiler.dart'package:test/lib.dart': Error: line 3 pos 1: library handler failed
import '/Applications/dart/dart-sdk/lib/_internal/compiler/compiler.dart';
^
'file:///Users/justinfagnani/dart/test/bin/main.dart': Error: line 2 pos 1: library handler failed
import 'package:test/lib.dart';
^
// test/bin/main.dart:
import 'package:test/lib.dart';
main() {
print(sayHi("Joe"));
}
// test/lib/lib.dart:
library lib;
import '/Applications/dart/dart-sdk/lib/_internal/compiler/compiler.dart';
sayHi(name) => "Hi $name";
The text was updated successfully, but these errors were encountered: