Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Sep 25, 2024
1 parent 4248fc5 commit 6cadeaf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 2 additions & 3 deletions vlib/v/gen/c/assign.v
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions vlib/v/tests/assign/assign_array_fixed_from_union_test.v
Original file line number Diff line number Diff line change
@@ -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]!
}

0 comments on commit 6cadeaf

Please sign in to comment.