mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix fixed array of map (#18347)
This commit is contained in:
parent
254ed1766c
commit
d3c679bdcb
@ -2530,6 +2530,12 @@ pub fn (mut c Checker) expr(node_ ast.Expr) ast.Type {
|
||||
|
||||
unwrapped_expr_type := c.unwrap_generic(node.expr_type)
|
||||
tsym := c.table.sym(unwrapped_expr_type)
|
||||
if tsym.kind == .array_fixed {
|
||||
info := tsym.info as ast.ArrayFixed
|
||||
// for dumping fixed array we must registed the fixed array struct to return from function
|
||||
c.table.find_or_register_array_fixed(info.elem_type, info.size, info.size_expr,
|
||||
true)
|
||||
}
|
||||
type_cname := if node.expr_type.has_flag(.option) {
|
||||
'_option_${tsym.cname}'
|
||||
} else {
|
||||
|
@ -170,7 +170,24 @@ fn (mut g Gen) fixed_array_init(node ast.ArrayInit, array_type Type, var_name st
|
||||
g.expr(node.default_expr)
|
||||
}
|
||||
} else {
|
||||
g.write('0')
|
||||
elem_sym := g.table.final_sym(node.elem_type)
|
||||
if elem_sym.kind == .map {
|
||||
info := array_type.unaliased_sym.info as ast.ArrayFixed
|
||||
map_info := elem_sym.map_info()
|
||||
g.expr(ast.MapInit{
|
||||
key_type: map_info.key_type
|
||||
value_type: map_info.value_type
|
||||
})
|
||||
for _ in 1 .. info.size {
|
||||
g.write(', ')
|
||||
g.expr(ast.MapInit{
|
||||
key_type: map_info.key_type
|
||||
value_type: map_info.value_type
|
||||
})
|
||||
}
|
||||
} else {
|
||||
g.write('0')
|
||||
}
|
||||
}
|
||||
g.write('}')
|
||||
if need_tmp_var {
|
||||
|
13
vlib/v/tests/fixed_array_map_test.v
Normal file
13
vlib/v/tests/fixed_array_map_test.v
Normal file
@ -0,0 +1,13 @@
|
||||
fn test_main() {
|
||||
mut arr := [22]map[string]string{}
|
||||
arr[0]['key'] = 'value'
|
||||
arr[1]['key2'] = 'value2'
|
||||
dump(arr[0])
|
||||
assert dump(arr[0]) == {
|
||||
'key': 'value'
|
||||
}
|
||||
assert dump(arr[1]) == {
|
||||
'key2': 'value2'
|
||||
}
|
||||
assert dump(arr).len == 22
|
||||
}
|
Loading…
Reference in New Issue
Block a user