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

ast/parser: fix else handling with ref heads #5425

Merged

Conversation

srenatus
Copy link
Contributor

@srenatus srenatus commented Nov 29, 2022

There was a case that slipped through the parser, but failed at a later stage. It's now caught early.

image

anderseknert
anderseknert previously approved these changes Nov 29, 2022
@srenatus srenatus marked this pull request as draft November 29, 2022 11:27
@srenatus
Copy link
Contributor Author

Unexpected test fallout... I'll have a look in a bit.

@@ -644,9 +644,12 @@ func (p *Parser) parseRules() []*Rule {
}

if p.s.tok == tokens.Else {

if r := rule.Head.Ref(); len(r) > 1 && !r[len(r)-1].Value.IsGround() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a non-ref-head rule, like

a := 1 if true

the ref is Ref{VarTerm("a")}, and that would be a false-positive for the check if done without len(r)>1.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
@srenatus srenatus marked this pull request as ready for review November 29, 2022 12:34
@srenatus srenatus merged commit 7540f11 into open-policy-agent:main Nov 29, 2022
@srenatus srenatus deleted the sr/ast/parser-else-handling branch November 29, 2022 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants