Skip to content

Commit

Permalink
Fix scheduling statements that don't create bindings (#40)
Browse files Browse the repository at this point in the history
Ensure that definitions are added even if no var is being defined.

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
  • Loading branch information
anakrish authored Nov 10, 2023
1 parent 0af8b6e commit 02c6c6b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,12 +776,21 @@ impl<'a> Analyzer<'a> {
)?;
self.process_comprs(&comprs[..], scope, first_use, &mut used_vars)?;
let check_first_use = *op == AssignOp::ColEq;
for var in self.gather_assigned_vars(lhs, scope, check_first_use, first_use)? {
let assigned_vars =
self.gather_assigned_vars(lhs, scope, check_first_use, first_use)?;

for var in &assigned_vars {
definitions.push(Definition {
var,
used_vars: used_vars.clone(),
});
}
if assigned_vars.is_empty() {
definitions.push(Definition {
var: "",
used_vars: used_vars.clone(),
});
}
}
{
let (mut used_vars, comprs) = Self::gather_used_vars_comprs_index_vars(
Expand All @@ -792,12 +801,20 @@ impl<'a> Analyzer<'a> {
)?;
let check_first_use = false;
self.process_comprs(&comprs[..], scope, first_use, &mut used_vars)?;
for var in self.gather_assigned_vars(rhs, scope, check_first_use, first_use)? {
let assigned_vars =
self.gather_assigned_vars(rhs, scope, check_first_use, first_use)?;
for var in &assigned_vars {
definitions.push(Definition {
var,
used_vars: used_vars.clone(),
});
}
if assigned_vars.is_empty() {
definitions.push(Definition {
var: "",
used_vars: used_vars.clone(),
});
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/opa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ fn run_opa_tests() -> Result<()> {
}
}

std::fs::write(path.join(format!("query{n}.text")), case.query.as_bytes())?;

println!("failed");
entry.1 += 1;
n += 1;
Expand Down

0 comments on commit 02c6c6b

Please sign in to comment.