From b6044b88620a3201ae487aadf20d8c798604b8fb Mon Sep 17 00:00:00 2001 From: Stephan Renatus Date: Fri, 28 May 2021 13:45:59 +0200 Subject: [PATCH] topdown: move arg count below ir.Empty() ...to avoid a panic at run time. Fixes #3501. Signed-off-by: Stephan Renatus --- .../functions/test-functions-unused-arg.yaml | 12 ++++++++++++ topdown/eval.go | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 test/cases/testdata/functions/test-functions-unused-arg.yaml diff --git a/test/cases/testdata/functions/test-functions-unused-arg.yaml b/test/cases/testdata/functions/test-functions-unused-arg.yaml new file mode 100644 index 0000000000..2d28050574 --- /dev/null +++ b/test/cases/testdata/functions/test-functions-unused-arg.yaml @@ -0,0 +1,12 @@ +cases: +- data: + modules: + - | + package p + + f(x) { + r = input.that_is_not_there + } + note: basic call + query: data.p.f(1) + want_result: [] diff --git a/topdown/eval.go b/topdown/eval.go index 3c7bca3f4b..54791c4f6c 100644 --- a/topdown/eval.go +++ b/topdown/eval.go @@ -1506,12 +1506,12 @@ func (e evalFunc) eval(iter unifyIterator) error { return err } - argCount := len(ir.Rules[0].Head.Args) - if ir.Empty() { return nil } + argCount := len(ir.Rules[0].Head.Args) + if len(ir.Else) > 0 && e.e.unknown(e.e.query[e.e.index], e.e.bindings) { // Partial evaluation of ordered rules is not supported currently. Save the // expression and continue. This could be revisited in the future.