From ff6413acd3c24c8d28170ed0b3494efaf5ea637b Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sat, 6 Dec 2025 06:16:37 -0300 Subject: [PATCH] cgen: fix map value init with array fixed const (fix #25887) (#25902) --- vlib/v/gen/c/cgen.v | 3 +++ .../builtin_arrays/array_fixed_map_values_test.v | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 vlib/v/tests/builtin_arrays/array_fixed_map_values_test.v diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index af4911b78..1cc2c706e 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -5122,6 +5122,9 @@ fn (mut g Gen) map_init(node ast.MapInit) { g.expr_with_cast(expr, node.val_types[i], unwrap_val_typ) } else if node.val_types[i].has_flag(.option) || node.val_types[i] == ast.none_type { g.expr_with_opt(expr, node.val_types[i], unwrap_val_typ) + } else if expr !is ast.ArrayInit && value_sym.info is ast.ArrayFixed { + tmpvar := g.expr_with_var(expr, node.val_types[i], false) + g.fixed_array_var_init(tmpvar, false, value_sym.info.elem_type, value_sym.info.size) } else { g.expr(expr) } diff --git a/vlib/v/tests/builtin_arrays/array_fixed_map_values_test.v b/vlib/v/tests/builtin_arrays/array_fixed_map_values_test.v new file mode 100644 index 000000000..965a980f5 --- /dev/null +++ b/vlib/v/tests/builtin_arrays/array_fixed_map_values_test.v @@ -0,0 +1,11 @@ +const invalid = [0, 0, 0]! + +fn test_main() { + m := { + '1,1,1': [1, 1, 1]! + '?': invalid + '2,2,2': [2, 2, 2]! + } + assert m['1,1,1'] == [1, 1, 1]! + assert m['?'] == invalid +} -- 2.39.5