feat: Else blocks in definitions

- ensure both run-to-completion and suspendable rule execution stop evaluating
  bodies once one succeeds so later else branches are skipped
- test cases

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
Anand Krishnamoorthi
2025-12-05 11:40:43 -06:00
parent e9a50bcfd5
commit a232b13e50
3 changed files with 300 additions and 2 deletions

View File

@@ -96,6 +96,10 @@ impl RegoVM {
}
}
}
// Once a body in this definition succeeds, remaining bodies
// are treated as else-branches and must not be evaluated.
break;
}
Err(_e) => {
continue;
@@ -502,7 +506,14 @@ impl RegoVM {
}
}
frame_data.current_body_index += 1;
if let Some(definition_bodies) = rule_info
.definitions
.get(frame_data.current_definition_index)
{
frame_data.current_body_index = definition_bodies.len();
} else {
frame_data.current_body_index += 1;
}
self.rule_frame_schedule_segment(frame_data, rule_info)
}