parser: update check for non mut types in fn

pull/5204/head
Swastik Baranwal 2020-06-03 21:17:18 +05:30 committed by GitHub
parent 962bbf1c60
commit d286f67220
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 3 deletions

View File

@ -1,5 +1,5 @@
vlib/v/checker/tests/function_arg_mutable_err.v:1:18: error: mutable arguments are only allowed for arrays, maps, and structs
return values instead: `fn foo(n mut int) {` => `fn foo(n int) int {`
return values instead: `fn foo(mut n int) {` => `fn foo(n int) int {`
1 | fn mod_ptr(mut a int) {
| ~~~
2 | a = 77

View File

@ -1,5 +1,5 @@
vlib/v/checker/tests/mut_int.v:1:14: error: mutable arguments are only allowed for arrays, maps, and structs
return values instead: `fn foo(n mut int) {` => `fn foo(n int) int {`
return values instead: `fn foo(mut n int) {` => `fn foo(n int) int {`
1 | fn foo(mut x int) {
| ~~~
2 | }

View File

@ -458,7 +458,7 @@ fn (mut p Parser) check_fn_mutable_arguments(typ table.Type, pos token.Position)
sym := p.table.get_type_symbol(typ)
if sym.kind !in [.array, .struct_, .map, .placeholder] && !typ.is_ptr() {
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 {`', pos)
'return values instead: `fn foo(mut n $sym.name) {` => `fn foo(n $sym.name) $sym.name {`', pos)
}
}