1
0
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:
Felipe Pena 2023-01-07 07:04:04 -03:00 committed by GitHub
parent 2aced13942
commit a60f34e6dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -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)

View 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]
}