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

mutable args: don't allow primitives

This commit is contained in:
Alexander Medvednikov
2019-07-24 15:24:32 +02:00
parent 7ea688aa43
commit 6b2063a2ea
3 changed files with 39 additions and 6 deletions

View File

@@ -71,7 +71,7 @@ fn modify_array(a mut []int) {
a << 888
}
fn test_mut() {
fn test_mut_array() {
mut nums := [1, 2, 3]
modify_array(mut nums)
assert nums.len == 4
@@ -81,6 +81,31 @@ fn test_mut() {
assert nums[3] == 888
}
fn mod_struct(user mut User) {
user.age++
}
struct User {
mut:
age int
}
fn test_mut_struct() {
mut user := User{18}
mod_struct(mut user)
assert user.age == 19
}
fn mod_ptr(buf mut byteptr) {
buf[0] = 77
}
fn test_mut_ptr() {
buf := malloc(10)
mod_ptr(mut buf)
assert buf[0] == 77
}
fn test_fns() {
// no asserts for now, just test function declarations above
}