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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user