From afba1500361005f02dfd7423a04f215839f59557 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Tue, 12 Dec 2023 03:07:52 -0800 Subject: fix(tvix/eval): builtins.elemAt: propagate catchables This commit fixes builtins.elemAt so it propagates catchables like cppnix does. Change-Id: Ieca5e128da17e78af0b14dae4a28a1ff8796e4f2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10308 Autosubmit: Adam Joseph Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/eval/src/builtins/mod.rs | 6 ++++++ .../src/tests/tvix_tests/eval-okay-builtins-elemAt-catchable.exp | 1 + .../src/tests/tvix_tests/eval-okay-builtins-elemAt-catchable.nix | 1 + 3 files changed, 8 insertions(+) create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-builtins-elemAt-catchable.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-builtins-elemAt-catchable.nix (limited to 'tvix/eval') diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index d85d6567ea..58fe6bbbcb 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -291,6 +291,12 @@ mod pure_builtins { #[builtin("elemAt")] async fn builtin_elem_at(co: GenCo, xs: Value, i: Value) -> Result { + if xs.is_catchable() { + return Ok(xs); + } + if i.is_catchable() { + return Ok(i); + } let xs = xs.to_list()?; let i = i.as_int()?; if i < 0 { diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-elemAt-catchable.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-elemAt-catchable.exp new file mode 100644 index 0000000000..c508d5366f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-elemAt-catchable.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-elemAt-catchable.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-elemAt-catchable.nix new file mode 100644 index 0000000000..97be4b013c --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-elemAt-catchable.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.elemAt (throw "fred") 0)).success -- cgit 1.4.1