From 4accdd0afdc96071a6bf819c1e1ddc35ece3e78c Mon Sep 17 00:00:00 2001 From: Lach Date: Wed, 26 Aug 2020 14:04:13 +0500 Subject: [PATCH] fix(evaluator): wrap TLA evaluation in state --- crates/jrsonnet-evaluator/src/lib.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/jrsonnet-evaluator/src/lib.rs b/crates/jrsonnet-evaluator/src/lib.rs index f1314f4e..3eb6a8f3 100644 --- a/crates/jrsonnet-evaluator/src/lib.rs +++ b/crates/jrsonnet-evaluator/src/lib.rs @@ -330,13 +330,15 @@ impl EvaluationState { /// If passed value is function then call with set TLA pub fn with_tla(&self, val: Val) -> Result { - Ok(match val { - Val::Func(func) => func.evaluate_map( - self.create_default_context()?, - &self.settings().tla_vars, - true, - )?, - v => v, + self.run_in_state(|| { + Ok(match val { + Val::Func(func) => func.evaluate_map( + self.create_default_context()?, + &self.settings().tla_vars, + true, + )?, + v => v, + }) }) } } @@ -408,7 +410,7 @@ impl EvaluationState { pub fn add_tla_code(&self, name: Rc, code: Rc) -> Result<()> { let value = self.evaluate_snippet_raw(Rc::new(PathBuf::from(format!("tla_code {}", name))), code)?; - self.add_ext_var(name, value); + self.add_tla(name, value); Ok(()) }