From 719a3b5de3d7617dca457f5cc7d865326db17929 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Mon, 4 Apr 2022 06:20:54 +0300 Subject: [PATCH] cgen: fix fixed arrays assignment in translated code --- vlib/v/gen/c/assign.v | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vlib/v/gen/c/assign.v b/vlib/v/gen/c/assign.v index 3980970076..76f49cedaa 100644 --- a/vlib/v/gen/c/assign.v +++ b/vlib/v/gen/c/assign.v @@ -211,8 +211,9 @@ fn (mut g Gen) gen_assign_stmt(node_ ast.AssignStmt) { g.expr(val) g.writeln(';}') } - } else if node.op == .assign + } else if node.op == .assign && !g.pref.translated && (is_fixed_array_init || (right_sym.kind == .array_fixed && val is ast.Ident)) { + // Fixed arrays mut v_var := '' arr_typ := styp.trim('*') if is_fixed_array_init { @@ -402,7 +403,9 @@ fn (mut g Gen) gen_assign_stmt(node_ ast.AssignStmt) { } g.is_shared = var_type.has_flag(.shared_f) if !cloned { - if is_fixed_array_var { + if is_fixed_array_var && !g.pref.translated { + // TODO Instead of the translated check, check if it's a pointer already + // and don't generate memcpy & typ_str := g.typ(val_type).trim('*') ref_str := if val_type.is_ptr() { '' } else { '&' } g.write('memcpy(($typ_str*)')