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:
parent
1728e4c73e
commit
c9e8dd56c2
@ -889,7 +889,7 @@ fn (mut g Gen) gen_cross_var_assign(node &ast.AssignStmt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast.IndexExpr {
|
ast.IndexExpr {
|
||||||
sym := g.table.sym(left.left_type)
|
sym := g.table.sym(g.table.unaliased_type(left.left_type))
|
||||||
if sym.kind == .array {
|
if sym.kind == .array {
|
||||||
info := sym.info as ast.Array
|
info := sym.info as ast.Array
|
||||||
elem_typ := g.table.sym(info.elem_type)
|
elem_typ := g.table.sym(info.elem_type)
|
||||||
|
13
vlib/v/tests/cross_assign_aliased_array_test.v
Normal file
13
vlib/v/tests/cross_assign_aliased_array_test.v
Normal 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])
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user