diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 3c1f5cebe7..9c32cd8d43 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -307,11 +307,13 @@ pub fn (c mut Checker) method_call_expr(method_call_expr mut ast.MethodCallExpr) return info.elem_type } if method := c.table.type_find_method(typ_sym, name) { - if method_call_expr.args.len < method.args.len - 1 { - c.error('too few arguments in call to `${typ_sym.name}.$name`', method_call_expr.pos) + no_args := method.args.len - 1 + min_required_args := method.args.len - if method.is_variadic && method.args.len > 1 { 2 } else { 1 } + if method_call_expr.args.len < min_required_args { + c.error('too few arguments in call to `${typ_sym.name}.$name` ($method_call_expr.args.len instead of $min_required_args)', method_call_expr.pos) } - else if !method.is_variadic && method_call_expr.args.len > method.args.len + 1 { - c.error('too many arguments in call to `${typ_sym.name}.$name` ($method_call_expr.args.len instead of $method.args.len)', method_call_expr.pos) + else if !method.is_variadic && method_call_expr.args.len > no_args { + c.error('too many arguments in call to `${typ_sym.name}.$name` ($method_call_expr.args.len instead of $no_args)', method_call_expr.pos) } // if name == 'clone' { // println('CLONE nr args=$method.args.len') diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 45918de0f4..de42eb5be4 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -137,6 +137,7 @@ fn (p mut Parser) fn_decl() ast.FnDecl { name: name args: args return_type: return_type + is_variadic: is_variadic }) } else {