1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: make the errors for call expression shared/mut mismatches more detailed

This commit is contained in:
Delyan Angelov 2022-03-16 22:45:22 +02:00
parent 7f62346213
commit 7a4715288c
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -352,32 +352,12 @@ fn (mut c Checker) anon_fn(mut node ast.AnonFn) ast.Type {
} }
pub fn (mut c Checker) call_expr(mut node ast.CallExpr) ast.Type { pub fn (mut c Checker) call_expr(mut node ast.CallExpr) ast.Type {
// First check everything that applies to both fns and methods
// TODO merge logic from method_call and fn_call // TODO merge logic from method_call and fn_call
/* // First check everything that applies to both fns and methods
for i, call_arg in node.args {
if call_arg.is_mut {
c.fail_if_immutable(call_arg.expr)
if !arg.is_mut {
tok := call_arg.share.str()
c.error('`$node.name` parameter `$arg.name` is not `$tok`, `$tok` is not needed`',
call_arg.expr.pos())
} else if arg.typ.share() != call_arg.share {
c.error('wrong shared type', call_arg.expr.pos())
}
} else {
if arg.is_mut && (!call_arg.is_mut || arg.typ.share() != call_arg.share) {
tok := call_arg.share.str()
c.error('`$node.name` parameter `$arg.name` is `$tok`, you need to provide `$tok` e.g. `$tok arg${i+1}`',
call_arg.expr.pos())
}
}
}
*/
// Now call `method_call` or `fn_call` for specific checks.
old_inside_fn_arg := c.inside_fn_arg old_inside_fn_arg := c.inside_fn_arg
c.inside_fn_arg = true c.inside_fn_arg = true
mut continue_check := true mut continue_check := true
// Now call `method_call` or `fn_call` for specific checks.
typ := if node.is_method { typ := if node.is_method {
c.method_call(mut node) c.method_call(mut node)
} else { } else {
@ -810,7 +790,8 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
call_arg.expr.pos()) call_arg.expr.pos())
} else { } else {
if param.typ.share() != call_arg.share { if param.typ.share() != call_arg.share {
c.error('wrong shared type', call_arg.expr.pos()) c.error('wrong shared type `$call_arg.share.str()`, expected: `$param.typ.share().str()`',
call_arg.expr.pos())
} }
if to_lock != '' && !param.typ.has_flag(.shared_f) { if to_lock != '' && !param.typ.has_flag(.shared_f) {
c.error('$to_lock is `shared` and must be `lock`ed to be passed as `mut`', c.error('$to_lock is `shared` and must be `lock`ed to be passed as `mut`',
@ -1299,7 +1280,8 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
arg.expr.pos()) arg.expr.pos())
} else { } else {
if param_share != arg.share { if param_share != arg.share {
c.error('wrong shared type', arg.expr.pos()) c.error('wrong shared type `$arg.share.str()`, expected: `$param_share.str()`',
arg.expr.pos())
} }
if to_lock != '' && param_share != .shared_t { if to_lock != '' && param_share != .shared_t {
c.error('$to_lock is `shared` and must be `lock`ed to be passed as `mut`', c.error('$to_lock is `shared` and must be `lock`ed to be passed as `mut`',