mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
planner: fix IR for fixpoint case (#5276)
Previously, the planner didn't account for the variable to become known in the process of planning term b. In the case here, foo became known when planning the ref `input.foos[foo]`, the rhs of the `foo = input.foos[foo]` unification. Fixes #5271. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
This commit is contained in:
@@ -1090,12 +1090,21 @@ func (p *Planner) planUnifyVar(a ast.Var, b *ast.Term, iter planiter) error {
|
||||
}
|
||||
|
||||
return p.planTerm(b, func() error {
|
||||
target := p.newLocal()
|
||||
p.vars.Put(a, target)
|
||||
p.appendStmt(&ir.AssignVarStmt{
|
||||
Source: p.ltarget,
|
||||
Target: target,
|
||||
})
|
||||
// `a` may have become known while planning b, like in `a = input.x[a]`
|
||||
la, ok := p.vars.GetOp(a)
|
||||
if ok {
|
||||
p.appendStmt(&ir.EqualStmt{
|
||||
A: la,
|
||||
B: p.ltarget,
|
||||
})
|
||||
} else {
|
||||
target := p.newLocal()
|
||||
p.vars.Put(a, target)
|
||||
p.appendStmt(&ir.AssignVarStmt{
|
||||
Source: p.ltarget,
|
||||
Target: target,
|
||||
})
|
||||
}
|
||||
return iter()
|
||||
})
|
||||
}
|
||||
|
||||
+26
-1
@@ -18,4 +18,29 @@ cases:
|
||||
[x | x := 1] = [foo]
|
||||
}
|
||||
want_result:
|
||||
- x: 1
|
||||
- x: 1
|
||||
- note: ir/fixpoint key/value (negative)
|
||||
query: 'data.test.p = x'
|
||||
input:
|
||||
foos: ["foo"]
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
p {
|
||||
some foo
|
||||
foo == input.foos[foo]
|
||||
}
|
||||
want_result: []
|
||||
- note: ir/fixpoint key/value
|
||||
query: 'data.test.p = x'
|
||||
input:
|
||||
foos: [2, 1, 0]
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
p = foo {
|
||||
some foo
|
||||
foo == input.foos[foo]
|
||||
}
|
||||
want_result:
|
||||
- x: 1
|
||||
|
||||
Reference in New Issue
Block a user