mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix nested fixed array instantiation (#18357)
This commit is contained in:
parent
e97aff8742
commit
125921db66
@ -172,6 +172,7 @@ fn (mut g Gen) fixed_array_init(node ast.ArrayInit, array_type Type, var_name st
|
||||
} else {
|
||||
elem_sym := g.table.final_sym(node.elem_type)
|
||||
if elem_sym.kind == .map {
|
||||
// fixed array for map -- [N]map[key_type]value_type
|
||||
info := array_type.unaliased_sym.info as ast.ArrayFixed
|
||||
map_info := elem_sym.map_info()
|
||||
g.expr(ast.MapInit{
|
||||
@ -185,6 +186,21 @@ fn (mut g Gen) fixed_array_init(node ast.ArrayInit, array_type Type, var_name st
|
||||
value_type: map_info.value_type
|
||||
})
|
||||
}
|
||||
} else if elem_sym.kind == .array_fixed {
|
||||
// nested fixed array -- [N][N]type
|
||||
info := array_type.unaliased_sym.info as ast.ArrayFixed
|
||||
arr_info := elem_sym.array_fixed_info()
|
||||
g.expr(ast.ArrayInit{
|
||||
typ: node.elem_type
|
||||
elem_type: arr_info.elem_type
|
||||
})
|
||||
for _ in 1 .. info.size {
|
||||
g.write(', ')
|
||||
g.expr(ast.ArrayInit{
|
||||
typ: node.elem_type
|
||||
elem_type: arr_info.elem_type
|
||||
})
|
||||
}
|
||||
} else {
|
||||
g.write('0')
|
||||
}
|
||||
|
8
vlib/v/tests/multiple_arr_fixed_test.v
Normal file
8
vlib/v/tests/multiple_arr_fixed_test.v
Normal file
@ -0,0 +1,8 @@
|
||||
fn test_main() {
|
||||
mut arr := [2][3][2]map[string]string{}
|
||||
arr[0][0][1]['key'] = 'value'
|
||||
dump(arr)
|
||||
assert arr[0][0][1] == {
|
||||
'key': 'value'
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user