mirror of
https://github.com/vlang/v.git
synced 2025-09-13 01:16:02 -04:00
parent
031ed0fa63
commit
43e27d2443
@ -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.write('${ret_elem_styp} ${tmp_map_expr_result_name} = ')
|
||||||
g.expr(expr.expr)
|
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 {
|
else {
|
||||||
if closure_var_decl != '' {
|
if closure_var_decl != '' {
|
||||||
g.write('${closure_var_decl} = ')
|
g.write('${closure_var_decl} = ')
|
||||||
|
13
vlib/v/tests/builtin_arrays/array_map_to_fixed_array_test.v
Normal file
13
vlib/v/tests/builtin_arrays/array_map_to_fixed_array_test.v
Normal file
@ -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)}' == '[]'
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user