mirror of
https://github.com/vlang/v.git
synced 2025-09-17 19:36:35 -04:00
This commit is contained in:
parent
d7bc216713
commit
53d7a55424
@ -4215,6 +4215,13 @@ fn (mut c Checker) find_obj_definition(obj ast.ScopeObject) !ast.Expr {
|
|||||||
if mut expr is ast.Ident {
|
if mut expr is ast.Ident {
|
||||||
return c.find_definition(expr)
|
return c.find_definition(expr)
|
||||||
}
|
}
|
||||||
|
if mut expr is ast.ComptimeCall && expr.is_compile_value {
|
||||||
|
if expr.result_type == ast.bool_type {
|
||||||
|
return ast.BoolLiteral{
|
||||||
|
val: expr.compile_value.bool()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if !expr.is_pure_literal() {
|
if !expr.is_pure_literal() {
|
||||||
return error('definition of `${name}` is unknown at compile time')
|
return error('definition of `${name}` is unknown at compile time')
|
||||||
}
|
}
|
||||||
|
10
vlib/v/tests/if_comptime_check_const_test.v
Normal file
10
vlib/v/tests/if_comptime_check_const_test.v
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
const x = $d('x', true)
|
||||||
|
|
||||||
|
fn test_main() {
|
||||||
|
a := $if x {
|
||||||
|
1
|
||||||
|
} $else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
assert a == 1
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user