From 2af8174e2e36d4c96f612e92b3e00c3330fb56fa Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Tue, 12 Dec 2023 20:49:57 -0800 Subject: fix(tvix/eval): builtins.match: propagate catchables Change-Id: I14c9e625c91369e10d0c00380dca992811ae9059 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10346 Reviewed-by: sterni Autosubmit: Adam Joseph Tested-by: BuildkiteCI --- tvix/eval/src/builtins/mod.rs | 12 ++++++++++-- .../eval-okay-builtins-match-propagate-catchables.exp | 1 + .../eval-okay-builtins-match-propagate-catchables.nix | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-builtins-match-propagate-catchables.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-builtins-match-propagate-catchables.nix (limited to 'tvix') diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index 6cdb434f42b4..7cc2732ecfd9 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -766,8 +766,16 @@ mod pure_builtins { #[builtin("match")] async fn builtin_match(co: GenCo, regex: Value, str: Value) -> Result { - let s = str.to_str()?; - let re = regex.to_str()?; + let s = str; + if s.is_catchable() { + return Ok(s); + } + let s = s.to_str()?; + let re = regex; + if re.is_catchable() { + return Ok(re); + } + let re = re.to_str()?; let re: Regex = Regex::new(&format!("^{}$", re.as_str())).unwrap(); match re.captures(&s) { Some(caps) => Ok(Value::List( diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-match-propagate-catchables.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-match-propagate-catchables.exp new file mode 100644 index 000000000000..c508d5366f70 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-match-propagate-catchables.exp @@ -0,0 +1 @@ +false diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-match-propagate-catchables.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-match-propagate-catchables.nix new file mode 100644 index 000000000000..8d00994b60f5 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-match-propagate-catchables.nix @@ -0,0 +1 @@ +(builtins.tryEval (builtins.match (throw "foo") ".*")).success -- cgit 1.4.1