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

make the new mut check work with fn foo(mut bar)

This commit is contained in:
Alexander Medvednikov 2019-07-25 13:59:00 +02:00
parent 9ccd3bde01
commit 2ad0d0200d
2 changed files with 11 additions and 2 deletions

View File

@ -678,6 +678,7 @@ fn (p mut Parser) fn_args(f mut Fn) {
} }
} }
// foo *(1, 2, 3, mut bar)*
fn (p mut Parser) fn_call_args(f *Fn) *Fn { fn (p mut Parser) fn_call_args(f *Fn) *Fn {
// p.gen('(') // p.gen('(')
// println('fn_call_args() name=$f.name args.len=$f.args.len') // println('fn_call_args() name=$f.name args.len=$f.args.len')
@ -725,7 +726,15 @@ fn (p mut Parser) fn_call_args(f *Fn) *Fn {
p.error('`$arg.name` is a key_mut argument, you need to provide a variable to modify: `$f.name(... mut a...)`') p.error('`$arg.name` is a key_mut argument, you need to provide a variable to modify: `$f.name(... mut a...)`')
} }
p.check(.key_mut) p.check(.key_mut)
} var_name := p.lit
v := p.cur_fn.find_var(var_name)
if v.name == '' {
p.error('`$arg.name` is a key_mut argument, you need to provide a variable to modify: `$f.name(... mut a...)`')
}
if !v.is_changed {
p.cur_fn.mark_var_changed(v)
}
}
p.expected_type = arg.typ p.expected_type = arg.typ
typ := p.bool_expression() typ := p.bool_expression()
// Optimize `println`: replace it with `printf` to avoid extra allocations and // Optimize `println`: replace it with `printf` to avoid extra allocations and

View File

@ -92,7 +92,7 @@ mut:
fn test_mut_struct() { fn test_mut_struct() {
mut user := User{18} mut user := User{18}
mod_struct(mut user) mod_struct(mut user)
assert user.age == 19 assert user.age == 19
} }