mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix default initialization of option array with none values (#17536)
This commit is contained in:
parent
b6c4e88462
commit
b4f0bb247d
@ -361,7 +361,11 @@ fn (mut g Gen) array_init_with_fields(node ast.ArrayInit, elem_type Type, is_amp
|
||||
g.write(' (voidptr)${tmp})')
|
||||
} else if node.has_default {
|
||||
g.write('&(${elem_styp}[]){')
|
||||
g.expr_with_cast(node.default_expr, node.default_type, node.elem_type)
|
||||
if node.elem_type.has_flag(.option) {
|
||||
g.expr_with_opt(node.default_expr, node.default_type, node.elem_type)
|
||||
} else {
|
||||
g.expr_with_cast(node.default_expr, node.default_type, node.elem_type)
|
||||
}
|
||||
g.write('})')
|
||||
} else if node.has_len && node.elem_type.has_flag(.option) {
|
||||
g.write('&')
|
||||
|
10
vlib/v/tests/option_array_init_test.v
Normal file
10
vlib/v/tests/option_array_init_test.v
Normal file
@ -0,0 +1,10 @@
|
||||
fn test_main() {
|
||||
a := []?int{len: 3, init: none}
|
||||
mut t := a[0]
|
||||
assert t == none
|
||||
t = a[1]
|
||||
assert t == none
|
||||
t = a[2]
|
||||
assert t == none
|
||||
assert a.len == 3
|
||||
}
|
Loading…
Reference in New Issue
Block a user