mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix array initialization with options (#17562)
This commit is contained in:
parent
a0b3379d4a
commit
b19052949f
@ -50,9 +50,13 @@ fn (mut g Gen) array_init(node ast.ArrayInit, var_name string) {
|
||||
g.write('string_clone(')
|
||||
g.expr(expr)
|
||||
g.write(')')
|
||||
} else {
|
||||
if node.elem_type.has_flag(.option) {
|
||||
g.expr_with_opt(expr, node.expr_types[i], node.elem_type)
|
||||
} else {
|
||||
g.expr_with_cast(expr, node.expr_types[i], node.elem_type)
|
||||
}
|
||||
}
|
||||
if i != len - 1 {
|
||||
if i > 0 && i & 7 == 0 { // i > 0 && i % 8 == 0
|
||||
g.writeln(',')
|
||||
|
11
vlib/v/tests/option_array_test.v
Normal file
11
vlib/v/tests/option_array_test.v
Normal file
@ -0,0 +1,11 @@
|
||||
fn test_main() {
|
||||
a := [?int(1), 0, 2]
|
||||
mut t := a[0]
|
||||
assert t? == 1
|
||||
t = a[1]
|
||||
assert t? == 0
|
||||
t = a[2]
|
||||
assert t? == 2
|
||||
|
||||
_ := [?int(none), none]
|
||||
}
|
Loading…
Reference in New Issue
Block a user