Fix panic when parsing varags (#6940)
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
parent
84b00564f4
commit
5ddd1dcf0f
|
@ -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))
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue