1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix cross assign with aliased array (#18830)

This commit is contained in:
yuyi 2023-07-10 15:40:48 +08:00 committed by GitHub
parent 1728e4c73e
commit c9e8dd56c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -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)

View File

@ -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])
}