about summary refs log tree commit diff
path: root/tvix/eval/src/vm
diff options
context:
space:
mode:
authorAdam Joseph <adam@westernsemico.com>2023-12-12T11·45-0800
committerclbot <clbot@tvl.fyi>2023-12-12T16·57+0000
commitfc963033ae0f28a387d6aebcc1e827439f6653ef (patch)
treea558df784931aa8745a59e66a59e260e62b6724e /tvix/eval/src/vm
parent990c4e727f000e7db94e9b1367a55dbbfca68d65 (diff)
fix(tvix/eval): `?`: propagate catchables r/7189
This commit fixes out `?` operator so it correctly propagates
catchables.

Change-Id: Iebaa153a8492101ee3ddd29893c98730ff331547
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10317
Autosubmit: Adam Joseph <adam@westernsemico.com>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/vm')
-rw-r--r--tvix/eval/src/vm/mod.rs24
1 files changed, 16 insertions, 8 deletions
diff --git a/tvix/eval/src/vm/mod.rs b/tvix/eval/src/vm/mod.rs
index 44a29ba86f9d..5b9aecb8d440 100644
--- a/tvix/eval/src/vm/mod.rs
+++ b/tvix/eval/src/vm/mod.rs
@@ -707,16 +707,24 @@ impl<'o> VM<'o> {
                 }
 
                 OpCode::OpHasAttr => {
-                    let key = self.stack_pop().to_str().with_span(&frame, self)?;
-                    let result = match self.stack_pop() {
-                        Value::Attrs(attrs) => attrs.contains(key.as_str()),
+                    let key = self.stack_pop();
+                    let attrs = self.stack_pop();
+                    if key.is_catchable() {
+                        self.stack.push(key);
+                    } else if attrs.is_catchable() {
+                        self.stack.push(attrs);
+                    } else {
+                        let key = key.to_str().with_span(&frame, self)?;
+                        let result = match attrs {
+                            Value::Attrs(attrs) => attrs.contains(key.as_str()),
 
-                        // Nix allows use of `?` on non-set types, but
-                        // always returns false in those cases.
-                        _ => false,
-                    };
+                            // Nix allows use of `?` on non-set types, but
+                            // always returns false in those cases.
+                            _ => false,
+                        };
 
-                    self.stack.push(Value::Bool(result));
+                        self.stack.push(Value::Bool(result));
+                    }
                 }
 
                 OpCode::OpConcat => {