Skip to content
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

Closed
justinfagnani opened this issue Nov 8, 2012 · 5 comments
Closed

Absolute imports fail when used in a package #6612

justinfagnani opened this issue Nov 8, 2012 · 5 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. closed-as-intended Closed as the reported issue is expected behavior

Comments

@justinfagnani
Copy link
Contributor

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";

@iposva-google
Copy link
Contributor

Justin, can you please try with "file:///Applications/dart/..." and report your experience?


Added NeedsInfo label.

@justinfagnani
Copy link
Contributor Author

It works with file:///

@iposva-google
Copy link
Contributor

Thanks for verifying. This behaves as expected, since you are passing a relative URI to the import.


cc @peter-ahe-google.
Added AsDesigned label.

@peter-ahe-google
Copy link
Contributor

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:
  metadata import uri (as identifier)? combinator* ‘;’
  ;

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.

@peter-ahe-google
Copy link
Contributor

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}";

@justinfagnani justinfagnani added Type-Defect area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. closed-as-intended Closed as the reported issue is expected behavior labels Nov 8, 2012
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. closed-as-intended Closed as the reported issue is expected behavior
Projects
None yet
Development

No branches or pull requests

3 participants