format: Add support for and/or logical expressions - #9006
Merged
johanfylling merged 4 commits intoAug 13, 2026
Conversation
* fold and/or after a not-body operand * reject brace-led and/or lhs operands * report brace-led and/or rhs operands * name whole operand in brace-led hints Signed-off-by: Johan Fylling <johan.dev@fylling.se>
Fixes: open-policy-agent#8683 Signed-off-by: Johan Fylling <johan.dev@fylling.se>
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
sspaink
reviewed
Aug 12, 2026
|
|
||
| import future.keywords.and | ||
| import future.keywords.or | ||
|
|
Member
There was a problem hiding this comment.
p if {
(input.a | input.b) or input.c
}
formats as:
p if {
input.a | input.b or input.c
}
The parentheses are required here otherwise it parses as a set comprehension, an edge case only happens when (input.a | input.b) or input.c is alone in the body and not inline.
Recommended fix is to add isUnionExpr(expr) to logicalOperandNeedsParens
Contributor
Author
There was a problem hiding this comment.
Ugh! These freakin' comprehensions 🤬. Nice catch! 👍
Contributor
Author
There was a problem hiding this comment.
Fixed in 59dc118
The fix applies a bit broader than for just the and/or operators, as this was a more general issue.
sspaink
approved these changes
Aug 13, 2026
…owing an opening brace (`{`) ambiguous with a comprehension
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
johanfylling
force-pushed
the
and_or/formatter
branch
from
August 13, 2026 14:34
59dc118 to
ef14587
Compare
Benchmark Comparison (`48bb309719d039dd725d0c4ba2614e784ec28596` vs `ce44e0705e1c278a1cd1ba79291c448c8c717ae6`)
This comment was automatically generated by the benchmarks workflow. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #8683