mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix array_init generated code for reference var (#16894)
This commit is contained in:
parent
2aced13942
commit
a60f34e6dd
@ -25,6 +25,9 @@ fn (mut g Gen) array_init(node ast.ArrayInit, var_name string) {
|
|||||||
len := node.exprs.len
|
len := node.exprs.len
|
||||||
if array_type.unaliased_sym.kind == .array_fixed {
|
if array_type.unaliased_sym.kind == .array_fixed {
|
||||||
g.fixed_array_init(node, array_type, var_name)
|
g.fixed_array_init(node, array_type, var_name)
|
||||||
|
if is_amp {
|
||||||
|
g.write(')')
|
||||||
|
}
|
||||||
} else if len == 0 {
|
} else if len == 0 {
|
||||||
// `[]int{len: 6, cap:10, init:22}`
|
// `[]int{len: 6, cap:10, init:22}`
|
||||||
g.array_init_with_fields(node, elem_type, is_amp, shared_styp, var_name)
|
g.array_init_with_fields(node, elem_type, is_amp, shared_styp, var_name)
|
||||||
|
10
vlib/v/tests/assert_with_array_ref_test.v
Normal file
10
vlib/v/tests/assert_with_array_ref_test.v
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
fn test_main() {
|
||||||
|
myu16 := u16(50)
|
||||||
|
size_of_u16 := sizeof(u16)
|
||||||
|
|
||||||
|
mut asu8 := unsafe { &u8(malloc(size_of_u16)) }
|
||||||
|
|
||||||
|
asu8 = &[myu16]! // look this
|
||||||
|
|
||||||
|
assert unsafe { asu8.vbytes(int(size_of_u16)) } == [u8(50), 0]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user