v icon indicating copy to clipboard operation
v copied to clipboard

constant value not accepted as array size if defined in const block with $if clause

Open mp81ss opened this issue 3 years ago • 0 comments

Describe the bug

`import os

const ( buf_size = $if windows { os.max_path_len * 2 } $else { os.max_path_len } )

fn main() { mut buf := [buf_size]u8{} println(buf.len) } `

Expected Behavior

The array size (positive) dumped to screen

Current Behavior

`bug.v:9:17: error: fixed size cannot be zero or negative (fixed_size: 0)

9 |     mut buf := [buf_size]u8{}
  |                 ~~~~~~~~

Reproduction Steps

code example above

Possible Solution

Correctly handle constants declared in const block even when $if is used

Additional Information/Context

No response

V version

V 0.3.3 15cb18c

Environment details (OS name and version, etc.)

Windows 10 64 bit

mp81ss avatar Mar 06 '23 11:03 mp81ss