diff --git a/vlib/v/checker/tests/mut_int.out b/vlib/v/checker/tests/mut_int.out new file mode 100644 index 0000000000..d56c441b63 --- /dev/null +++ b/vlib/v/checker/tests/mut_int.out @@ -0,0 +1,6 @@ +panic: compilation failed: vlib/v/tests/inout/mut_int.v:1:12: error: mutable arguments are only allowed for arrays, maps, and structs +return values instead: `fn foo(n mut int) {` => `fn foo(n int) int {` + 1 | fn foo(mut x int) { + | ^ + 2 | } + 3 | diff --git a/vlib/v/checker/tests/mut_int.vv b/vlib/v/checker/tests/mut_int.vv new file mode 100644 index 0000000000..a268c5acbb --- /dev/null +++ b/vlib/v/checker/tests/mut_int.vv @@ -0,0 +1,5 @@ +fn foo(mut x int) { +} + +fn main() { +} diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 63b9b47fc1..707f3ef8ad 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -221,8 +221,8 @@ fn (mut p Parser) fn_decl() ast.FnDecl { continue } sym := p.table.get_type_symbol(arg.typ) - if sym.kind !in [.array, .struct_, .map, .placeholder] && arg.typ != table.t_type && - !arg.typ.is_ptr() { + // if sym.kind !in [.array, .struct_, .map, .placeholder] && arg.typ != table.t_type && !arg.typ.is_ptr() { + if sym.kind !in [.array, .struct_, .map, .placeholder] && arg.typ != table.t_type { p.error_with_pos('mutable arguments are only allowed for arrays, maps, and structs\n' + 'return values instead: `fn foo(n mut int) {` => `fn foo(n int) int {`', arg.pos) } @@ -396,7 +396,8 @@ fn (mut p Parser) fn_args() ([]table.Arg, bool) { } if p.tok.kind == .comma { if is_variadic { - p.error_with_pos('cannot use ...(variadic) with non-final parameter no $arg_no', pos) + p.error_with_pos('cannot use ...(variadic) with non-final parameter no $arg_no', + pos) } p.next() } @@ -450,7 +451,8 @@ fn (mut p Parser) fn_args() ([]table.Arg, bool) { } // if typ.typ.kind == .variadic && p.tok.kind == .comma { if is_variadic && p.tok.kind == .comma { - p.error_with_pos('cannot use ...(variadic) with non-final parameter $arg_name', arg_pos[i]) + p.error_with_pos('cannot use ...(variadic) with non-final parameter $arg_name', + arg_pos[i]) } } if p.tok.kind != .rpar {