-
Notifications
You must be signed in to change notification settings - Fork 421
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
How to use/import a specific module? #13915
Comments
I might get to this today if someone doesn't get to it first. Incidentally, I'm uncertain if it would be worth adding the answer to the modules primer, since there seems to be a lot more pieces than would normally be covered |
Okay, this is what I think you're asking: module M {
module M {
module M {
module M {
module S {
proc foo() {
writeln("A");
}
}
import < >; // To get each of the specific foos
foo();
} // M.M.M.M
module S {
proc foo() {
writeln("B");
}
}
} // M.M.M
module S {
proc foo() {
writeln("C");
}
}
} // M.M
module S {
proc foo() {
writeln("D");
}
}
} // M We do not have a way to disambiguate S from that particular location today. We search up scopes for module name and go with the first best answer - given that there is no "unique" path (from the perspective of naming) to each of the S's that are further away, you'll first find the match in the closest scope - W.r.t the crate references, we similarly do not have a strategy to do what you are asking. I think it would be reasonable to open feature requests for both something like |
I agree. It is important that There's a slightly overlapping issue of how a keyword like |
Discussion of proposed additional disambiguation syntax from Rust: The Great Module Adventure Continues. Rust has a similar problem to Chapel's What does Python do for each of these cases? |
@lydia-duncan / @BryantLam / @mppf: Can this be closed now with the new support for |
Yes, the story with
|
This issue asks if there should be syntax to differentiate use/import of modules at different places in the module hierarchy (e.g. root, submodule, sibling of parent module, ...). Such a feature could resolve certain unintended behaviors such as when a module with a conflicting name is added to a library (described in #14014 (comment) ).
Summary of Problem
Follow-on to #12923, #13524, #13536 (comment), #11262
I need a way to disambiguate a
use
orimport
statement when the module hierarchy and viable search targets look like this:and
Please cover all cases so that I can
import S
where S is a sibling of M andimport L
where L is a child of M, for each M = grandparent, parent, itself (if I wanted to rename myself inside M due to a conflict like this example), child, grandchild, this Mason package's main module, and other modules in the module path.I believe these are the solutions in Rust (todo: verify):
To kick off some discussion with a notional filesystem-based syntax:
and so on. This analogy breaks down pretty quickly when actually using the dot:
import package(dot)..(dot)S
* Not sure what to do with this, especially due to #13524 (comment). Is a package a module? Is
package
a keyword to wrap a set of modules?When just doing
import M
, the behavior would be a combination of: look for submodules, then look through the module search path. I don't think there's any concerns with that since it follows the intent of #12923.The text was updated successfully, but these errors were encountered: