v icon indicating copy to clipboard operation
v copied to clipboard

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

Open raw-bin opened this issue 7 months ago • 0 comments

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 avatar Jun 29 '24 20:06 raw-bin