Skip to content
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

Module import at lower directory level requires directory name to import #22937

Open
BadaBingBee opened this issue Nov 21, 2024 · 3 comments
Open
Labels
Bug This tag is applied to issues which reports bugs. Module Lookup Problem Bugs/feature requests, that are related to looking up modules/mismatches in module names/paths. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@BadaBingBee
Copy link

BadaBingBee commented Nov 21, 2024

Describe the bug

project_root/
├── src/
│   └── backend/
│       └── index.v
└── index.v

-- index.v
import src.backend

the above import works but this import throws a compile error:
-- index.v
import backend

index.v:5:1: builder error: cannot import module "backend" (not found)

Reproduction Steps

--- src/backend.v

module backend

pub struct User {
...
}

--- index.v

import src.backend

Expected Behavior

expected this import to work:
--- index.v

import backend

Current Behavior

-- index.v
import backend

...throws an error:
index.v:5:1: builder error: cannot import module "backend" (not found)

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.8 58fc4de

Environment details (OS name and version, etc.)

Fedora Linux 41

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@BadaBingBee BadaBingBee added the Bug This tag is applied to issues which reports bugs. label Nov 21, 2024
@spytheman
Copy link
Member

Note: that is without a v.mod file at the top of the project.

@spytheman spytheman added Module Lookup Problem Bugs/feature requests, that are related to looking up modules/mismatches in module names/paths. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. labels Nov 21, 2024
@BadaBingBee
Copy link
Author

Note: that is without a v.mod file at the top of the project.

Actually occurs with or without the v.mod file (at the top of the project).

@jorgeluismireles
Copy link

I put your folders and files inside my current project and worked (Ubuntu).

I have a v.mod file inside. Then I rename the file tov.modxin order to not to be found and then I got errors:

index.v:4:21: error: undefined ident: `src.backend.user`
    2 | 
    3 | fn main() {
    4 |     println('${backend.user}')
      |                        ~~~~
    5 | }

Try including a v.mod file sibling of index.v, with this content:

Module {
	name: 'your-name',
	description: "Your description",
	dependencies: [],
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Module Lookup Problem Bugs/feature requests, that are related to looking up modules/mismatches in module names/paths. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
None yet
Development

No branches or pull requests

3 participants