Skip to content

doc: Need to properly document the use of v.mod as relative module anchor #16570

@shnorbluk

Description

@shnorbluk

Describe the bug

Here is a simplified version of my application:

main.v

import myapp.common
fn main() {
	a := common.SampleParameters {}
}

myapp/common/structs.v

module common
pub struct SampleParameters {}

Expected Behavior

The program should compile. As explained in https://github.com/vlang/v/blob/master/doc/docs.md#create-modules, "You can create modules anywhere."

Current Behavior

$ v run main.v
main.v:3:2: warning: unused variable: `a`
    1 | import myapp.common
    2 | fn main() {
    3 |     a := common.SampleParameters {}
      |     ^
    4 | }
main.v:3:14: error: unknown type `myapp.common.SampleParameters`
    1 | import myapp.common
    2 | fn main() {
    3 |     a := common.SampleParameters {}
      |                 ~~~~~~~~~~~~~~~~~~~
    4 | }

Reproduction Steps

Write the 2 files in the given arborescence and try to compile it.

Possible Solution

By searching in examples, I found that nested submodules (with 2 levels of subdirectories) were put inside a modules directory. If you put my second file in modules/myapp/common/structs.v, it works. So there are 2 hypotheses:

  • either you consider that all modules, except main, are expected to be put in a modules directory, and it should be clearly explained in documentation
  • either it's a bug and all directories in the project are considered as a module, as said in documentation

Please notice that first level directories outside modules directories are considered as modules, but not deeper ones.

Additional Information/Context

No response

V version

V 0.3.2 675a1be

Environment details (OS name and version, etc.)

$ v doctor OS: windows, Microsoft Windows 10 Enterprise v19044 64-bit Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz CC version: Error: exec failed (CreateProcess) with code 2: Le fichier spécifié est introuvable. cmd: cc --version getwd: D:\checksum.v vmodules: C:\Users\me\.vmodules vroot: D:\v vexe: D:\v\v.exe vexe mtime: 2022-11-29 17:31:02 is vroot writable: true is vmodules writable: true V full version: V 0.3.2 675a1be Git version: git version 2.38.1.windows.1 Git vroot status: 0.3-1005-g675a1be9 (3 commit(s) behind V master) .git/config present: true thirdparty/tcc status: thirdparty-windows-amd64 cb89a4fe

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions