diff --git a/examples/submodule/main.v b/examples/submodule/main.v new file mode 100644 index 0000000000..e1ae1dbafa --- /dev/null +++ b/examples/submodule/main.v @@ -0,0 +1,7 @@ +import mymodules { add_xy } +import mymodules.submodule { sub_xy } + +fn main() { + println(add_xy(2, 3)) // expected: 5 + println(sub_xy(10, 7)) // expected: 3 +} diff --git a/examples/submodule/mymodules/main_functions.v b/examples/submodule/mymodules/main_functions.v new file mode 100644 index 0000000000..0697d36d25 --- /dev/null +++ b/examples/submodule/mymodules/main_functions.v @@ -0,0 +1,5 @@ +module mymodule + +pub fn add_xy(x int, y int) int { + return x + y +} diff --git a/examples/submodule/mymodules/submodule/sub_functions.v b/examples/submodule/mymodules/submodule/sub_functions.v new file mode 100644 index 0000000000..15448ecec4 --- /dev/null +++ b/examples/submodule/mymodules/submodule/sub_functions.v @@ -0,0 +1,5 @@ +module submodule + +pub fn sub_xy(x int, y int) int { + return x - y +} diff --git a/vlib/v/util/module.v b/vlib/v/util/module.v index b16e791ee7..0742ebd2f0 100644 --- a/vlib/v/util/module.v +++ b/vlib/v/util/module.v @@ -32,7 +32,7 @@ pub fn qualify_module(pref &pref.Preferences, mod string, file_path string) stri if mod == 'main' { return mod } - clean_file_path := file_path.all_before_last('/') + clean_file_path := file_path.all_before_last(os.path_separator) // relative module (relative to working directory) // TODO: find most stable solution & test with -usecache if clean_file_path.replace(os.getwd() + os.path_separator, '') == mod { @@ -110,5 +110,13 @@ pub fn mod_path_to_full_name(pref &pref.Preferences, mod string, path string) ?s } } } + if os.is_abs_path(pref.path) && os.is_abs_path(path) && os.is_dir(path) { // && path.contains(mod ) + rel_mod_path := path.replace(pref.path.all_before_last(os.path_separator) + + os.path_separator, '') + if rel_mod_path != path { + full_mod_name := rel_mod_path.replace(os.path_separator, '.') + return full_mod_name + } + } return error('module not found') }