From 2883b2d4bd948e090d46cee361bd69d6282d618c Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Wed, 13 Dec 2023 04:17:25 -0800 Subject: fix(tvix/eval): propagate catchables in string interpolations Change-Id: I13d7ce0c7328a8e6fbc6d2c4ff5c4fe6095b96ea Reviewed-on: https://cl.tvl.fyi/c/depot/+/10357 Autosubmit: Adam Joseph Reviewed-by: sterni Tested-by: BuildkiteCI --- .../eval-okay-catchable-in-string-interpolation.exp | 1 + .../eval-okay-catchable-in-string-interpolation.nix | 1 + tvix/eval/src/vm/mod.rs | 12 ++++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-string-interpolation.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-string-interpolation.nix (limited to 'tvix') diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-string-interpolation.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-string-interpolation.exp new file mode 100644 index 000000000000..c508d5366f70 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-string-interpolation.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-string-interpolation.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-string-interpolation.nix new file mode 100644 index 000000000000..7a0cf1670994 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-catchable-in-string-interpolation.nix @@ -0,0 +1 @@ +(builtins.tryEval ("${toString 3} ${throw "bob"}")).success diff --git a/tvix/eval/src/vm/mod.rs b/tvix/eval/src/vm/mod.rs index 6c11997db1f5..92fa0f00e3d3 100644 --- a/tvix/eval/src/vm/mod.rs +++ b/tvix/eval/src/vm/mod.rs @@ -983,8 +983,16 @@ impl<'o> VM<'o> { fn run_interpolate(&mut self, frame: &CallFrame, count: usize) -> EvalResult<()> { let mut out = String::new(); - for _ in 0..count { - out.push_str(self.stack_pop().to_str().with_span(frame, self)?.as_str()); + for i in 0..count { + let val = self.stack_pop(); + if val.is_catchable() { + for _ in (i + 1)..count { + self.stack.pop(); + } + self.stack.push(val); + return Ok(()); + } + out.push_str(val.to_str().with_span(frame, self)?.as_str()); } self.stack.push(Value::String(out.into())); -- cgit 1.4.1