From 014f44eab3de6d188d5f4f22677f9608308d1ae5 Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 30 Jul 2022 23:11:10 +0800 Subject: [PATCH] checker: improve error message of method_call_arg_no_mut_err.vv (#15281) --- vlib/v/checker/fn.v | 4 ++-- vlib/v/checker/tests/method_call_arg_no_mut_err.out | 2 +- vlib/v/checker/tests/method_call_arg_no_mut_err.vv | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index a69043c6f4..512799c340 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -1609,7 +1609,7 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { to_lock, pos := c.fail_if_immutable(arg.expr) if !param.is_mut { tok := arg.share.str() - c.error('`$node.name` parameter `$param.name` is not `$tok`, `$tok` is not needed`', + c.error('`$node.name` parameter ${i + 1} is not `$tok`, `$tok` is not needed`', arg.expr.pos()) } else { if param_share != arg.share { @@ -1624,7 +1624,7 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { } else { if param.is_mut { tok := arg.share.str() - c.error('method `$node.name` parameter `$param.name` is `$tok`, so use `$tok $arg.expr` instead', + c.error('method `$node.name` parameter ${i + 1} is `$tok`, so use `$tok $arg.expr` instead', arg.expr.pos()) } else { c.fail_if_unreadable(arg.expr, targ, 'argument') diff --git a/vlib/v/checker/tests/method_call_arg_no_mut_err.out b/vlib/v/checker/tests/method_call_arg_no_mut_err.out index 56b77f8a59..536310f723 100644 --- a/vlib/v/checker/tests/method_call_arg_no_mut_err.out +++ b/vlib/v/checker/tests/method_call_arg_no_mut_err.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/method_call_arg_no_mut_err.vv:25:14: error: method `alarm_fkt` parameter `a` is `mut`, so use `mut last` instead +vlib/v/checker/tests/method_call_arg_no_mut_err.vv:25:14: error: method `alarm_fkt` parameter 1 is `mut`, so use `mut last` instead 23 | c.arr << Alarm{} 24 | mut last := c.arr.last() 25 | c.alarm_fkt(last) diff --git a/vlib/v/checker/tests/method_call_arg_no_mut_err.vv b/vlib/v/checker/tests/method_call_arg_no_mut_err.vv index e4360ca2c6..f406de5f7b 100644 --- a/vlib/v/checker/tests/method_call_arg_no_mut_err.vv +++ b/vlib/v/checker/tests/method_call_arg_no_mut_err.vv @@ -1,6 +1,6 @@ module main -type Fkt = fn (mut a Alarm) +type Fkt = fn (mut Alarm) struct Alarm { x int