about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAdam Joseph <adam@westernsemico.com>2023-12-12T10·59-0800
committerclbot <clbot@tvl.fyi>2023-12-12T16·09+0000
commit990c4e727f000e7db94e9b1367a55dbbfca68d65 (patch)
tree5167d1166dea857618fd917bc45d9331d096ba3d
parent2949ee08f10f11a79af9b90933022ea40039462a (diff)
feat(tvix/eval): OpAttrsSelect should propagate catchables r/7188
Previously, using a catchable as either argument of OpAttrsSelect
would result in an unrecoverable error.  This commit matches cppnix
behavior by propagating the catchable.

Change-Id: I4877f4068ec2b823225f185290693c101d0b9c9e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10303
Tested-by: BuildkiteCI
Autosubmit: Adam Joseph <adam@westernsemico.com>
Reviewed-by: tazjin <tazjin@tvl.su>
-rw-r--r--tvix/eval/src/vm/mod.rs30
1 files changed, 19 insertions, 11 deletions
diff --git a/tvix/eval/src/vm/mod.rs b/tvix/eval/src/vm/mod.rs
index d57bd21e44c7..44a29ba86f9d 100644
--- a/tvix/eval/src/vm/mod.rs
+++ b/tvix/eval/src/vm/mod.rs
@@ -538,19 +538,27 @@ impl<'o> VM<'o> {
                 }
 
                 OpCode::OpAttrsSelect => {
-                    let key = self.stack_pop().to_str().with_span(&frame, self)?;
-                    let attrs = self.stack_pop().to_attrs().with_span(&frame, self)?;
+                    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 attrs = attrs.to_attrs().with_span(&frame, self)?;
 
-                    match attrs.select(key.as_str()) {
-                        Some(value) => self.stack.push(value.clone()),
+                        match attrs.select(key.as_str()) {
+                            Some(value) => self.stack.push(value.clone()),
 
-                        None => {
-                            return frame.error(
-                                self,
-                                ErrorKind::AttributeNotFound {
-                                    name: key.as_str().to_string(),
-                                },
-                            );
+                            None => {
+                                return frame.error(
+                                    self,
+                                    ErrorKind::AttributeNotFound {
+                                        name: key.as_str().to_string(),
+                                    },
+                                );
+                            }
                         }
                     }
                 }