vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.5k stars 2.15k forks source link

cannot use constants with values ​​obtained using `$d` as a condition in comptime `if` #21709

Closed StunxFS closed 6 days ago

StunxFS commented 1 week ago

Describe the bug

Cannot use constants with values ​​obtained using $d as a condition in comptime if.

Reproduction Steps

const x = $d('x', true)

$if x {
    println('x == true')
}

Expected Behavior

$ v run main.v
x == true

Current Behavior

main.v:3:5: error: definition of `x` is unknown at compile time
    1 | const x = $d('x', true)
    2 | 
    3 | $if x {
      |     ^
    4 |     print('x == true')
    5 | }

Possible Solution

No response

Additional Information/Context

If a literal is used, it works:

const x = true

$if x {
    println('x == true')
}

V version

V 0.4.6 be9d2b6

Environment details (OS name and version, etc.)

V Playground

[!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.