checker: variadic method fix

pull/4110/head
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 return info.elem_type
} }
if method := c.table.type_find_method(typ_sym, name) { if method := c.table.type_find_method(typ_sym, name) {
if method_call_expr.args.len < method.args.len - 1 { no_args := method.args.len - 1
c.error('too few arguments in call to `${typ_sym.name}.$name`', method_call_expr.pos) 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 { 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 $method.args.len)', method_call_expr.pos) 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' { // if name == 'clone' {
// println('CLONE nr args=$method.args.len') // println('CLONE nr args=$method.args.len')

View File

@ -137,6 +137,7 @@ fn (p mut Parser) fn_decl() ast.FnDecl {
name: name name: name
args: args args: args
return_type: return_type return_type: return_type
is_variadic: is_variadic
}) })
} }
else { else {