diff --git a/vlib/v/gen/c/assign.v b/vlib/v/gen/c/assign.v index 07be32d1365d4b..1041bc7bae592c 100644 --- a/vlib/v/gen/c/assign.v +++ b/vlib/v/gen/c/assign.v @@ -396,10 +396,9 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) { right_sym := g.table.sym(unwrapped_val_type) unaliased_right_sym := g.table.final_sym(unwrapped_val_type) is_fixed_array_var := unaliased_right_sym.kind == .array_fixed && val !is ast.ArrayInit - && (val in [ast.Ident, ast.IndexExpr, ast.CallExpr, ast.SelectorExpr, ast.DumpExpr, ast.InfixExpr] + && (val in [ast.Ident, ast.IndexExpr, ast.CallExpr, ast.SelectorExpr, ast.DumpExpr, ast.InfixExpr, ast.UnsafeExpr] || (val is ast.CastExpr && val.expr !is ast.ArrayInit) - || (val is ast.PrefixExpr && val.op == .arrow) - || (val is ast.UnsafeExpr && val.expr is ast.Ident)) && !g.pref.translated + || (val is ast.PrefixExpr && val.op == .arrow)) && !g.pref.translated g.is_assign_lhs = true g.assign_op = node.op diff --git a/vlib/v/tests/assign/assign_array_fixed_from_union_test.v b/vlib/v/tests/assign/assign_array_fixed_from_union_test.v new file mode 100644 index 00000000000000..bedf6c9cf15b43 --- /dev/null +++ b/vlib/v/tests/assign/assign_array_fixed_from_union_test.v @@ -0,0 +1,16 @@ +union Convertor { + su8_array_p [20]u8 + sint_array_p [5]int +} + +fn test_main() { + a := [1, 2, 3, 4, 5]! + p := voidptr(unsafe { &Convertor(&a[0]) }) + c := unsafe { &Convertor(p).su8_array_p } + dump(a) + dump(p) + dump(c) + assert a == [1, 2, 3, 4, 5]! + assert p != 0 + assert c == [u8(1), 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0]! +}