Skip to content

util: qualify modules relative to compilation project root (fix #27138) - #27219

Merged
medvednikov merged 1 commit into
masterfrom
worktree-fix-nested-vmod-import-27138
May 24, 2026
Merged

medvednikov merged 1 commit into
masterfrom
worktree-fix-nested-vmod-import-27138

Conversation

@medvednikov

Copy link
Copy Markdown
Member

Summary

Fixes #27138: when a project contains a subdirectory with its own v.mod, importing a submodule like import dep.mymod from the outer project failed with unknown enum dep.mymod.Color (type_idx=0) and unknown function: dep.mymod.color_name. The dependency's .v files were parsed but registered under the wrong qualified name (mymod instead of dep.mymod), because the inner v.mod was treated as the naming boundary in util.qualify_module.

The fix anchors mod_path_to_full_name to the v.mod that contains the current compilation (pref.path). When the resolved module directory lies inside that project root, the module name is computed relative to it, so a nested v.mod no longer shrinks names of its sub-modules. The existing standalone case (`cd dep && v .`) is preserved β€” it's covered by test_running_project_from_its_own_vmod_with_parent_vmod_works_issue_26828, which still passes.

Test plan

  • Reproduction from the issue now prints red / mymod.Point{...} / ok, with dep/v.mod present.
  • Same reproduction still works after deleting dep/v.mod (no regression in the workaround path).
  • Self-host: ./v -o v cmd/v runs cleanly for two iterations.
  • vlib/v/tests/modules/ β€” 19/19 pass (includes sub/sub_test.v which uses a nested v.mod inside a submodule).
  • vlib/v/tests/project_with_modules_having_submodules/ β€” 2/2 pass.
  • vlib/v/tests/projects_that_should_compile_test.v β€” all pass, including new test_importing_submodule_through_nested_vmod_works_issue_27138 regression test.
  • cmd/tools/vpm/ β€” 13/13 pass.

When a project has a subdirectory with its own `v.mod`, importing a
submodule like `import dep.mymod` from the outer project failed with
`unknown enum dep.mymod.Color (type_idx=0)` β€” the file was parsed but
registered under the wrong qualified name (`mymod` instead of
`dep.mymod`), because the inner `v.mod` was treated as the naming
boundary. Anchor `mod_path_to_full_name` to the v.mod that contains
`pref.path` so nested v.mod files no longer shrink module names.
@medvednikov
medvednikov merged commit e334642 into master May 24, 2026
4 of 179 checks passed
@JalonSolov
JalonSolov deleted the worktree-fix-nested-vmod-import-27138 branch July 28, 2026 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Types and functions from subdirectories with v.mod are invisible to cross-module importers

1 participant