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

Compilation failure for global array when array size is a const in another module #21762

Closed
raw-bin opened this issue Jun 29, 2024 · 0 comments · Fixed by #21900
Closed

Compilation failure for global array when array size is a const in another module #21762

raw-bin opened this issue Jun 29, 2024 · 0 comments · Fixed by #21900
Assignees
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@raw-bin
Copy link

raw-bin commented Jun 29, 2024

Describe the bug

Consider the following:

❯ fd -I -H
3.v
a/
a/a.v

3.v:


❯ cat 3.v
module main

import a

struct DummyStruct {
        dummy_item i32
}

__global (
        d [a.num_elements]DummyStruct
)

fn main() {}

a.v:

❯ cat a/a.v
module a

pub const num_elements = 10

Compiler invocation and error:

❯ v -enable-globals 3.v
==================
/tmp/v_501/3.01J1JS3A76SW7J937SDV473XT9.tmp.c:2067:2: error: unknown type name 'Array_fixed_main__DummyStruct_0'
 Array_fixed_main__DummyStruct_0  d = {0}; // global4
 ^
1 error generated.
...
==================
(Use `v -cg` to print the entire error message)

builder error:
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .

If const num_elements = 10 is in the main module then the compilation succeeds.

Reproduction Steps

See above.

Expected Behavior

Either the fact that it is invalid to use non-module-local const variables as array dimensions should be documented as such with a suitably information compiler error, or this should be supported and documented.

Current Behavior

See above.

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.6 23e3894

Environment details (OS name and version, etc.)

❯ neofetch --off
[email protected]
-------------------
OS: macOS 14.5 23F79 arm64
Host: Mac14,9
Kernel: 23.5.0
Uptime: 11 days, 12 hours, 1 min
Packages: 250 (port)
Shell: fish 3.7.1
Resolution: 5120x1440 , 3024x1964
DE: Aqua
WM: Quartz Compositor
WM Theme: Blue (Dark)
Terminal: tmux
CPU: Apple M2 Pro
GPU: Apple M2 Pro
Memory: 4667MiB / 32768MiB

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.

@raw-bin raw-bin added the Bug This tag is applied to issues which reports bugs. label Jun 29, 2024
@felipensp felipensp self-assigned this Jul 20, 2024
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants