Skip to content

Commit a74d932

Browse files
authored
cgen: fix fixed array return via local (#27350)
1 parent 839a409 commit a74d932

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

‎vlib/v/gen/c/cgen.v‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10883,13 +10883,7 @@ fn (mut g Gen) return_stmt(node ast.Return) {
1088310883
if node.exprs[0] is ast.Ident {
1088410884
g.writeln('{0};')
1088510885
typ := if node.exprs[0].is_auto_deref_var() { type0.deref() } else { type0 }
10886-
typ_sym := g.table.final_sym(typ)
10887-
if typ_sym.kind == .array_fixed
10888-
&& (typ_sym.info as ast.ArrayFixed).is_fn_ret {
10889-
g.write('memcpy(${tmpvar}.ret_arr, ${g.expr_string(expr0)}.ret_arr, sizeof(${g.styp(typ)}))')
10890-
} else {
10891-
g.write('memcpy(${tmpvar}.ret_arr, ${g.expr_string(expr0)}, sizeof(${g.styp(typ)}))')
10892-
}
10886+
g.write('memcpy(${tmpvar}.ret_arr, ${g.expr_string(expr0)}, sizeof(${g.styp(typ)}))')
1089310887
} else if expr0 in [ast.ArrayInit, ast.StructInit] {
1089410888
if expr0 is ast.ArrayInit && expr0.is_fixed && expr0.has_init {
1089510889
if expr0.init_expr.is_literal() {

‎vlib/v/tests/return_fixed_array_test.v‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,16 @@ fn test_returns_option_and_result_fixed_array() {
5757
}
5858
assert res == [59, 101, 200]!
5959
}
60+
61+
fn issue_27345_hud_rgba() [4]u8 {
62+
return [u8(1), 2, 3, 4]!
63+
}
64+
65+
fn issue_27345_shop_category_color() [4]u8 {
66+
col := issue_27345_hud_rgba()
67+
return col
68+
}
69+
70+
fn test_fixed_array_return_via_local_from_call() {
71+
assert issue_27345_shop_category_color() == [u8(1), 2, 3, 4]!
72+
}

0 commit comments

Comments
 (0)