Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

call expressions passing the input document as an operand are not rewritten correctly #2084

Closed
tsandall opened this issue Feb 10, 2020 · 0 comments · Fixed by #2259
Closed
Assignees
Labels

Comments

@tsandall
Copy link
Member

For example:

package play

f(x, y) {
   x[y]
}

p {        
    input.foo = _
    f(input, "bar")        # THIS STATEMENT IS NOT REWRITTEN PROPERLY
}

Tracing shows the issue:

Enter data.play = _
| Eval data.play = _
| Index data.play = _ (matched 1 rule)
| Index data.play = _ (matched 1 rule)
| Enter data.play.p
| | Eval input.foo = _
| | Eval data.play.f(input, "bar")   # THIS STATEMENT IS WRONG
-------8< SNIP 8<---------

The last expression shown in the trace above is incorrect. The first operand (input) should have been assigned to a local variable and then substituted in the call. If the call was to a built-in function the OPA would return an error (since it would end up passing a variable to the built-in function implementation, which is illegal.)

@tsandall tsandall added the bug label Feb 10, 2020
@tsandall tsandall self-assigned this Feb 10, 2020
@tsandall tsandall removed their assignment Feb 24, 2020
@ashutosh-narkar ashutosh-narkar self-assigned this Mar 31, 2020
ashutosh-narkar added a commit to ashutosh-narkar/opa that referenced this issue Apr 2, 2020
Earlier if a reference to the root of the input document was passed as operand in a call, it would not be rewritten to a local variable and substituted in the call. Refs to non-root input/data document would be rewritten. This was happening because we were updating the value of the input root ref term to a variable and as a result the compiler stage that rewrites the body of dynamic terms ('rewriteDynamicTerms') would not rewrite the input root ref. These changes modify the 'rewriteLocalVars' stage so that the value of root ref term is updated based on whether its value is an explicitly declared variable. If it isn't, then it will be rewritten in a later stage.

Fixes open-policy-agent#2084

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
tsandall pushed a commit that referenced this issue Apr 3, 2020
Earlier if a reference to the root of the input document was passed as operand in a call, it would not be rewritten to a local variable and substituted in the call. Refs to non-root input/data document would be rewritten. This was happening because we were updating the value of the input root ref term to a variable and as a result the compiler stage that rewrites the body of dynamic terms ('rewriteDynamicTerms') would not rewrite the input root ref. These changes modify the 'rewriteLocalVars' stage so that the value of root ref term is updated based on whether its value is an explicitly declared variable. If it isn't, then it will be rewritten in a later stage.

Fixes #2084

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants