mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix c error when use reserved keyword as if guard var (#12871)
This commit is contained in:
parent
f87f8ec3f7
commit
2f7ac7e407
@ -5332,10 +5332,11 @@ fn (mut g Gen) if_expr(node ast.IfExpr) {
|
||||
is_auto_heap = v.is_auto_heap
|
||||
}
|
||||
}
|
||||
left_var_name := c_name(branch.cond.var_name)
|
||||
if is_auto_heap {
|
||||
g.writeln('\t$base_type* $branch.cond.var_name = HEAP($base_type, *($base_type*)${var_name}.data);')
|
||||
g.writeln('\t$base_type* $left_var_name = HEAP($base_type, *($base_type*)${var_name}.data);')
|
||||
} else {
|
||||
g.writeln('\t$base_type $branch.cond.var_name = *($base_type*)${var_name}.data;')
|
||||
g.writeln('\t$base_type $left_var_name = *($base_type*)${var_name}.data;')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
vlib/v/tests/reserved_keywords_if_guard_test.v
Normal file
11
vlib/v/tests/reserved_keywords_if_guard_test.v
Normal file
@ -0,0 +1,11 @@
|
||||
fn array_n_opt(n int) ?[]int {
|
||||
return if n >= 0 { []int{len: n} } else { none }
|
||||
}
|
||||
|
||||
fn test_reserved_keyword_of_if_guard() {
|
||||
if array := array_n_opt(2) {
|
||||
assert array.len == 2
|
||||
} else {
|
||||
assert false
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user