checker: fix mut int check

pull/5190/head
Alexander Medvednikov 2020-06-03 10:36:52 +02:00
parent 6a0a2da05c
commit 199f4f006b
3 changed files with 17 additions and 4 deletions

View File

@ -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 |

View File

@ -0,0 +1,5 @@
fn foo(mut x int) {
}
fn main() {
}

View File

@ -221,8 +221,8 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
continue continue
} }
sym := p.table.get_type_symbol(arg.typ) sym := p.table.get_type_symbol(arg.typ)
if sym.kind !in [.array, .struct_, .map, .placeholder] && arg.typ != table.t_type && // if sym.kind !in [.array, .struct_, .map, .placeholder] && arg.typ != table.t_type && !arg.typ.is_ptr() {
!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' + 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) '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 p.tok.kind == .comma {
if is_variadic { 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() 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 typ.typ.kind == .variadic && p.tok.kind == .comma {
if is_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 { if p.tok.kind != .rpar {