fix: Disallow else blocks for set rules (#403)

else blocks following contains and old-style sets will raise
a parse error. Consistent with OPA.

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
Anand Krishnamoorthi
2025-04-29 11:14:37 -05:00
committed by GitHub
parent 6719456468
commit b11007a1be
2 changed files with 37 additions and 9 deletions

View File

@@ -1617,6 +1617,12 @@ impl<'source> Parser<'source> {
let bodies = self.parse_rule_bodies()?;
span.end = self.end;
if let RuleHead::Set { .. } = &head {
if let Some(RuleBody { span, .. }) = bodies.get(1) {
bail!(span.error("else cannot be used with set rules"));
}
}
if self.rego_v1 && bodies.is_empty() {
match &head {
RuleHead::Compr { assign, .. } | RuleHead::Func { assign, .. }