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

checker: variadic method fix

This commit is contained in:
Joe Conigliaro 2020-03-24 22:39:11 +11:00
parent f101e9b9e2
commit 9a8bd3f7fa
2 changed files with 7 additions and 4 deletions

View File

@ -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')

View File

@ -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 {