From 42c59b1276e1ad6e0800529a345a0602da216330 Mon Sep 17 00:00:00 2001 From: Stephan Renatus Date: Fri, 28 May 2021 15:13:19 +0200 Subject: [PATCH] topdown: deal with default functions (#3505) They aren't supported, but they can lead to a situation where ir.Empty() is false, but ir.Rules still has length 0. Signed-off-by: Stephan Renatus --- internal/wasm/sdk/test/e2e/exceptions.yaml | 1 + .../functions/test-functions-default.yaml | 21 +++++++++++++++++++ .../functions/test-functions-unused-arg.yaml | 2 +- topdown/eval.go | 4 +++- 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 test/cases/testdata/functions/test-functions-default.yaml diff --git a/internal/wasm/sdk/test/e2e/exceptions.yaml b/internal/wasm/sdk/test/e2e/exceptions.yaml index 8c3413b8c6..371d791a76 100644 --- a/internal/wasm/sdk/test/e2e/exceptions.yaml +++ b/internal/wasm/sdk/test/e2e/exceptions.yaml @@ -1 +1,2 @@ # Exception Format is : +"functions/default": "not supported in topdown, https://github.com/open-policy-agent/opa/issues/2445" \ No newline at end of file diff --git a/test/cases/testdata/functions/test-functions-default.yaml b/test/cases/testdata/functions/test-functions-default.yaml new file mode 100644 index 0000000000..00c7abcd29 --- /dev/null +++ b/test/cases/testdata/functions/test-functions-default.yaml @@ -0,0 +1,21 @@ +cases: +- data: + modules: + - | + package p.m + + default hello = false + + hello() = m { + m = input.message + 1 == 2 + m = "world" + } + h = m { + m = hello() + } + note: functions/default # not supported but shouldn't panic + query: data.p.m = x + want_result: + - x: + hello: false diff --git a/test/cases/testdata/functions/test-functions-unused-arg.yaml b/test/cases/testdata/functions/test-functions-unused-arg.yaml index 2d28050574..705984509d 100644 --- a/test/cases/testdata/functions/test-functions-unused-arg.yaml +++ b/test/cases/testdata/functions/test-functions-unused-arg.yaml @@ -7,6 +7,6 @@ cases: f(x) { r = input.that_is_not_there } - note: basic call + note: unused arg query: data.p.f(1) want_result: [] diff --git a/topdown/eval.go b/topdown/eval.go index 54791c4f6c..9b8fabe5ce 100644 --- a/topdown/eval.go +++ b/topdown/eval.go @@ -1506,7 +1506,9 @@ func (e evalFunc) eval(iter unifyIterator) error { return err } - if ir.Empty() { + // default functions aren't supported: + // https://github.com/open-policy-agent/opa/issues/2445 + if len(ir.Rules) == 0 { return nil }