Skip to content

Commit

Permalink
cgen: fix cross assign with aliased array (#18830)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Jul 10, 2023
1 parent 1728e4c commit c9e8dd5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/gen/c/assign.v
Expand Up @@ -889,7 +889,7 @@ fn (mut g Gen) gen_cross_var_assign(node &ast.AssignStmt) {
}
}
ast.IndexExpr {
sym := g.table.sym(left.left_type)
sym := g.table.sym(g.table.unaliased_type(left.left_type))
if sym.kind == .array {
info := sym.info as ast.Array
elem_typ := g.table.sym(info.elem_type)
Expand Down
13 changes: 13 additions & 0 deletions vlib/v/tests/cross_assign_aliased_array_test.v
@@ -0,0 +1,13 @@
pub type IntSlice = []int

pub fn (mut x IntSlice) swap(i int, j int) {
x[i], x[j] = x[j], x[i]
}

fn test_cross_assign_aliased_array() {
mut x := IntSlice([11, 22])
println(x)
x.swap(0, 1)
println(x)
assert x == IntSlice([22, 11])
}

0 comments on commit c9e8dd5

Please sign in to comment.