Skip to content

Commit

Permalink
topdown: deal with default functions (#3505)
Browse files Browse the repository at this point in the history
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 <stephan.renatus@gmail.com>
  • Loading branch information
srenatus committed May 28, 2021
1 parent 27e870d commit 42c59b1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions internal/wasm/sdk/test/e2e/exceptions.yaml
@@ -1 +1,2 @@
# Exception Format is <test name>: <reason>
"functions/default": "not supported in topdown, https://github.com/open-policy-agent/opa/issues/2445"
21 changes: 21 additions & 0 deletions 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
Expand Up @@ -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: []
4 changes: 3 additions & 1 deletion topdown/eval.go
Expand Up @@ -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
}

Expand Down

0 comments on commit 42c59b1

Please sign in to comment.