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

cgen: fix mutable array arguments (#5769)

This commit is contained in:
yuyi
2020-07-11 00:04:51 +08:00
committed by GitHub
parent 9fd0bc93f0
commit 0c9c66dd6b
4 changed files with 41 additions and 12 deletions

View File

@ -910,3 +910,25 @@ fn test_array_in_mut() {
array_in_mut(mut a)
assert a == [2,2]
}
// test array delete in function with mut argument
fn delete_nums(mut arr []int) {
arr.delete(0)
}
fn test_array_delete_in_mut() {
mut nums := [1, 2, 3]
delete_nums(mut nums)
assert nums == [2, 3]
}
// test array add in function with mut argument
fn add_nums(mut arr []int) {
arr << 4
}
fn test_array_add_in_mut() {
mut nums := [1, 2, 3]
add_nums(mut nums)
assert nums == [1, 2, 3, 4]
}