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:
parent
9ccd3bde01
commit
2ad0d0200d
@ -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 {
|
||||
// p.gen('(')
|
||||
// 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.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
|
||||
typ := p.bool_expression()
|
||||
// Optimize `println`: replace it with `printf` to avoid extra allocations and
|
||||
|
@ -92,7 +92,7 @@ mut:
|
||||
|
||||
fn test_mut_struct() {
|
||||
mut user := User{18}
|
||||
mod_struct(mut user)
|
||||
mod_struct(mut user)
|
||||
assert user.age == 19
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user