V version: 0.1.28 a8b0dfb
OS: ubuntu
What did you do?
I tried to compile a project in a directory like this:
mymodule
|__submodule1
|__submodule1.v
|__submodule2
|__submodule2.v
|__mymodule.v
test.v
in mymodule.v, submodules are imported :
module mymodule
import submodule1
import submodule2
pub fn test(){
submodule1.test()
submodule2.test()
}
and test.v defines the main entry and call the mymodule.test()
What did you expect to see?
test() called correctly
What did you see instead?
A builder error suggests that cannot import module "submodule1" (not found)
import submodule1 import submodule2
Shouldn't it be this instead?
import mymodule.submodule1
import mymodule.submodule2
~~~~~~~~~
Right. In general, it is import <module>.<submodule> and imports always start at the base of the modules even if you're inside the module tree. At least that is my understanding.
@spaceface777 I see, that solves the problem. In my understanding, when compiling mymodule.v the root dir is changed which is not the case.
No, @JalonSolov is right, module lookup starts from the root level (or from wherever you have a v.mod file)
The current behavior makes sense to me, because this way imports do not have to be changed if a file is moved into a submodule.
Most helpful comment
Right. In general, it is
import <module>.<submodule>and imports always start at the base of the modules even if you're inside the module tree. At least that is my understanding.