From 02c6c6b8274a8763dd57058a60337f8b78c42b9b Mon Sep 17 00:00:00 2001 From: Anand Krishnamoorthi <35780660+anakrish@users.noreply.github.com> Date: Thu, 9 Nov 2023 16:24:43 -0800 Subject: [PATCH] Fix scheduling statements that don't create bindings (#40) Ensure that definitions are added even if no var is being defined. Signed-off-by: Anand Krishnamoorthi --- src/scheduler.rs | 21 +++++++++++++++++++-- tests/opa/mod.rs | 2 ++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/scheduler.rs b/src/scheduler.rs index c1d548b2..3be76d43 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -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( @@ -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(), + }); + } } } } diff --git a/tests/opa/mod.rs b/tests/opa/mod.rs index a89747fa..31cd7c5c 100644 --- a/tests/opa/mod.rs +++ b/tests/opa/mod.rs @@ -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;