From d286f67220e480236332cd91231d523a4c0fb9d8 Mon Sep 17 00:00:00 2001 From: Swastik Baranwal Date: Wed, 3 Jun 2020 21:17:18 +0530 Subject: [PATCH] parser: update check for non mut types in fn --- vlib/v/checker/tests/function_arg_mutable_err.out | 2 +- vlib/v/checker/tests/mut_int.out | 2 +- vlib/v/parser/fn.v | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/vlib/v/checker/tests/function_arg_mutable_err.out b/vlib/v/checker/tests/function_arg_mutable_err.out index 7b57886ac2..6c31fb1433 100644 --- a/vlib/v/checker/tests/function_arg_mutable_err.out +++ b/vlib/v/checker/tests/function_arg_mutable_err.out @@ -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 diff --git a/vlib/v/checker/tests/mut_int.out b/vlib/v/checker/tests/mut_int.out index a79bd19f43..ce1abc705d 100644 --- a/vlib/v/checker/tests/mut_int.out +++ b/vlib/v/checker/tests/mut_int.out @@ -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 | } diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 86d754547d..ccd0b3eacc 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -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) } }