about summary refs log tree commit diff
path: root/tvix/eval/src/vm.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-14T11·34+0300
committertazjin <tazjin@tvl.su>2022-08-30T17·13+0000
commitcfe37d36f7977f93dd5b8441d691811bf2b6997b (patch)
tree761bb85c7b333e6d6739490a7e6f655c7c098ace /tvix/eval/src/vm.rs
parent76846fe22032546661cdf8649b8f898fc36e5270 (diff)
fix(tvix/eval): `or` should handle non-attrset values, too r/4543
If a nested attrpath encounters a non-set value, the sentinel value
denoting a lack of next values should be emitted. This mirrors the
behaviour of Nix.

Change-Id: Ia80443d5a11243cc6d98dcab1249a3f5fdf77e27
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6210
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/vm.rs')
-rw-r--r--tvix/eval/src/vm.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs
index d050fa8071..d18cd7977b 100644
--- a/tvix/eval/src/vm.rs
+++ b/tvix/eval/src/vm.rs
@@ -182,12 +182,16 @@ impl VM {
 
                 OpCode::OpAttrOrNotFound => {
                     let key = self.pop().to_string()?;
-                    let attrs = self.pop().to_attrs()?;
+                    let value = match self.pop() {
+                        Value::Attrs(attrs) => match attrs.select(key.as_str()) {
+                            Some(value) => value.clone(),
+                            None => Value::NotFound,
+                        },
 
-                    match attrs.select(key.as_str()) {
-                        Some(value) => self.push(value.clone()),
-                        None => self.push(Value::NotFound),
-                    }
+                        _ => Value::NotFound,
+                    };
+
+                    self.push(value);
                 }
 
                 OpCode::OpAttrsIsSet => {