mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
test: Add RVM compiler testing to ACI tests (#509)
code fixes:
- compiler: add `is_var_bound_in_current_scope` and use it in destructuring so
only the innermost scope blocks rebinding while still catching duplicates
within that block.
- rvm: treat `not` over undefined operands as a successful negation to match
interpreter semantics.
tests/aci:
migrate YAML cases to `data.policy.rule` queries with `{x: …}`
bindings, expand the harness to run interpreter plus RVM (with optional
skipping), align results to the binding format, add readable timing output,
and support a `--filter` flag for targeting cases.
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
committed by
GitHub
parent
a8a3a9809b
commit
12c083e29e
@@ -140,6 +140,14 @@ impl<'a> Compiler<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true when a variable is already bound in the innermost scope
|
||||
pub fn is_var_bound_in_current_scope(&self, var_name: &str) -> bool {
|
||||
self.scopes
|
||||
.last()
|
||||
.map(|scope| scope.bound_vars.contains_key(var_name))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Look up a variable in all scopes starting from innermost (like interpreter's lookup_local_var)
|
||||
pub fn lookup_local_var(&self, var_name: &str) -> Option<Register> {
|
||||
self.scopes
|
||||
|
||||
@@ -289,7 +289,7 @@ impl<'a> Compiler<'a> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if self.lookup_local_var(var_name).is_some() {
|
||||
if self.is_var_bound_in_current_scope(var_name) {
|
||||
bail!("Variable '{var_name}' already defined in current scope");
|
||||
}
|
||||
|
||||
|
||||
@@ -299,7 +299,10 @@ impl RegoVM {
|
||||
let operand_value = &self.registers[operand as usize];
|
||||
|
||||
if operand_value == &Value::Undefined {
|
||||
self.registers[dest as usize] = Value::Undefined;
|
||||
// In Rego, `not expr` succeeds when `expr` has no results.
|
||||
// When the operand evaluates to undefined we should treat it as
|
||||
// a successful negation instead of propagating undefined.
|
||||
self.registers[dest as usize] = Value::Bool(true);
|
||||
return Ok(InstructionOutcome::Continue);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user