diff --git a/vlib/v/checker/tests/mut_args_warning.out b/vlib/v/checker/tests/mut_args_warning.out new file mode 100644 index 0000000000..64f4802893 --- /dev/null +++ b/vlib/v/checker/tests/mut_args_warning.out @@ -0,0 +1,5 @@ +vlib/v/checker/tests/mut_args_warning.v:1:8: warning: use `mut f Foo` instead of `f mut Foo` + 1 | fn f(x mut []int) { x[0] = 1 } + | ~~~ + 2 | fn main() { + 3 | mut x := [0] diff --git a/vlib/v/checker/tests/mut_args_warning.vv b/vlib/v/checker/tests/mut_args_warning.vv new file mode 100644 index 0000000000..c29b27d455 --- /dev/null +++ b/vlib/v/checker/tests/mut_args_warning.vv @@ -0,0 +1,5 @@ +fn f(x mut []int) { x[0] = 1 } +fn main() { + mut x := [0] + f(mut x) +} diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 23e38e6d09..ece7aaaf94 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -415,6 +415,7 @@ fn (mut p Parser) fn_args() ([]table.Arg, bool) { } if p.tok.kind == .key_mut { // TODO remove old syntax + p.warn_with_pos('use `mut f Foo` instead of `f mut Foo`', p.tok.position()) is_mut = true } if p.tok.kind == .ellipsis {