Closed rchowinfoblox closed 3 years ago
As you said - NOT
should have higher affinity than AND
:
https://github.com/infobloxopen/seal/blob/master/pkg/parser/condition.go#L160-L172
PRECEDENCE_LOWEST
PRECEDENCE_OR // logical or
PRECEDENCE_AND // logical and
PRECEDENCE_NOT // logical not
PRECEDENCE_EQUALS // ==
PRECEDENCE_LESSGREATER // > or <
PRECEDENCE_SUM // +
PRECEDENCE_PRODUCT // *
PRECEDENCE_PREFIX // -X or !X
PRECEDENCE_CALL // myFunction(X)
The
NOT
operator (negation) is supposed to have higher precedence thanAND
operator. Suppose we have this (admittedly contrived) SEAL statement usingNOT
operator:The front-end SEAL compiler correctly parses the where condition, according to this SEAL compiler debug log:
But the back-end rego compiler generates incorrect rego:
The generated incorrect rego is the equivalent of
AND
having higher precedence:which is not the same as desired
NOT
having higher precedence: