Fix panic when parsing varags (#6940)

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
Julien Pivotto 2020-03-08 13:09:24 +01:00 committed by GitHub
parent 84b00564f4
commit 5ddd1dcf0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -544,6 +544,11 @@ func (p *parser) checkAST(node Node) (typ ValueType) {
for i, arg := range n.Args {
if i >= len(n.Func.ArgTypes) {
if n.Func.Variadic == 0 {
// This is not a vararg function so we should not check the
// type of the extra arguments.
break
}
i = len(n.Func.ArgTypes) - 1
}
p.expectType(arg, n.Func.ArgTypes[i], fmt.Sprintf("call to function %q", n.Func.Name))

View File

@ -2130,10 +2130,22 @@ var testExpr = []struct {
input: "floor(some_metric, other_metric)",
fail: true,
errMsg: "expected 1 argument(s) in call to \"floor\", got 2",
}, {
input: "floor(some_metric, 1)",
fail: true,
errMsg: "expected 1 argument(s) in call to \"floor\", got 2",
}, {
input: "floor(1)",
fail: true,
errMsg: "expected type instant vector in call to function \"floor\", got scalar",
}, {
input: "hour(some_metric, some_metric, some_metric)",
fail: true,
errMsg: "expected at most 1 argument(s) in call to \"hour\", got 3",
}, {
input: "time(some_metric)",
fail: true,
errMsg: "expected 0 argument(s) in call to \"time\", got 1",
}, {
input: "non_existent_function_far_bar()",
fail: true,