Skip to content

Commit ff6413a

Browse files
authored
cgen: fix map value init with array fixed const (fix #25887) (#25902)
1 parent 74d55ef commit ff6413a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

vlib/v/gen/c/cgen.v

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5122,6 +5122,9 @@ fn (mut g Gen) map_init(node ast.MapInit) {
51225122
g.expr_with_cast(expr, node.val_types[i], unwrap_val_typ)
51235123
} else if node.val_types[i].has_flag(.option) || node.val_types[i] == ast.none_type {
51245124
g.expr_with_opt(expr, node.val_types[i], unwrap_val_typ)
5125+
} else if expr !is ast.ArrayInit && value_sym.info is ast.ArrayFixed {
5126+
tmpvar := g.expr_with_var(expr, node.val_types[i], false)
5127+
g.fixed_array_var_init(tmpvar, false, value_sym.info.elem_type, value_sym.info.size)
51255128
} else {
51265129
g.expr(expr)
51275130
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const invalid = [0, 0, 0]!
2+
3+
fn test_main() {
4+
m := {
5+
'1,1,1': [1, 1, 1]!
6+
'?': invalid
7+
'2,2,2': [2, 2, 2]!
8+
}
9+
assert m['1,1,1'] == [1, 1, 1]!
10+
assert m['?'] == invalid
11+
}

0 commit comments

Comments
 (0)