diff --git a/vlib/v/gen/c/array.v b/vlib/v/gen/c/array.v index ead456b54cb809..a7ea7f3b397c64 100644 --- a/vlib/v/gen/c/array.v +++ b/vlib/v/gen/c/array.v @@ -576,6 +576,28 @@ fn (mut g Gen) gen_array_map(node ast.CallExpr) { g.write('${ret_elem_styp} ${tmp_map_expr_result_name} = ') g.expr(expr.expr) } + ast.SelectorExpr { + if expr.typ != ast.void_type && g.table.final_sym(expr.typ).kind == .array_fixed { + atype := g.styp(expr.typ) + if closure_var_decl != '' { + g.write('memcpy(&${closure_var_decl}, &') + g.expr(expr) + g.write(', sizeof(${atype}))') + } else { + g.writeln('${ret_elem_styp} ${tmp_map_expr_result_name};') + g.write('memcpy(&${tmp_map_expr_result_name}, &') + g.expr(expr) + g.write(', sizeof(${atype}))') + } + } else { + if closure_var_decl != '' { + g.write('${closure_var_decl} = ') + } else { + g.write('${ret_elem_styp} ${tmp_map_expr_result_name} = ') + } + g.expr(expr) + } + } else { if closure_var_decl != '' { g.write('${closure_var_decl} = ') diff --git a/vlib/v/tests/builtin_arrays/array_map_to_fixed_array_test.v b/vlib/v/tests/builtin_arrays/array_map_to_fixed_array_test.v new file mode 100644 index 00000000000000..8228b54d317fe4 --- /dev/null +++ b/vlib/v/tests/builtin_arrays/array_map_to_fixed_array_test.v @@ -0,0 +1,13 @@ +type Mat4 = [16]f32 + +struct GameObject { +mut: + transform Mat4 + children []&GameObject +} + +fn test_array_map_to_fixed_array() { + mut v1 := &GameObject{} + eprintln('children: ${v1.children.map(it.transform)}') + assert '${v1.children.map(it.transform)}' == '[]' +}