mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-28 03:05:04 -06:00
wasm: Fix planner to check call expression for false return value
The planner was not checking call expression results for false return values that ought to cause evaluation to fail. This meant that evaluation would continue to the next expression. Signed-off-by: Torin Sandall <torinsandall@gmail.com>
This commit is contained in:
@@ -678,7 +678,7 @@ func (p *Planner) planExprCall(e *ast.Expr, iter planiter) error {
|
||||
|
||||
if len(operands) == arity {
|
||||
// rule: f(x) = x { ... }
|
||||
// call: f(x) == 1 or f(x) # result not captured
|
||||
// call: f(x) # result not captured
|
||||
return p.planCallArgs(operands, 0, args, func(args []ir.Local) error {
|
||||
p.ltarget = p.newLocal()
|
||||
p.appendStmt(&ir.CallStmt{
|
||||
@@ -686,6 +686,19 @@ func (p *Planner) planExprCall(e *ast.Expr, iter planiter) error {
|
||||
Args: args,
|
||||
Result: p.ltarget,
|
||||
})
|
||||
|
||||
falsy := p.newLocal()
|
||||
|
||||
p.appendStmt(&ir.MakeBooleanStmt{
|
||||
Value: false,
|
||||
Target: falsy,
|
||||
})
|
||||
|
||||
p.appendStmt(&ir.NotEqualStmt{
|
||||
A: p.ltarget,
|
||||
B: falsy,
|
||||
})
|
||||
|
||||
return iter()
|
||||
})
|
||||
} else if len(operands) == arity+1 {
|
||||
|
||||
@@ -103,4 +103,20 @@ cases:
|
||||
package x
|
||||
f(x) = 1
|
||||
f(x) = 2
|
||||
want_error: var assignment conflict
|
||||
want_error: var assignment conflict
|
||||
- note: 'false result'
|
||||
query: data.test.p = x
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
f(x) = false
|
||||
p = true { f(1) }
|
||||
want_defined: false
|
||||
- note: 'negated false result'
|
||||
query: data.test.p = x
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
f(x) = false
|
||||
p = true { not f(1) }
|
||||
want_defined: true
|
||||
Reference in New Issue
Block a user