From 990c4e727f000e7db94e9b1367a55dbbfca68d65 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Tue, 12 Dec 2023 02:59:19 -0800 Subject: feat(tvix/eval): OpAttrsSelect should propagate catchables 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 Reviewed-by: tazjin --- tvix/eval/src/vm/mod.rs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'tvix/eval/src') 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(), + }, + ); + } } } } -- cgit 1.4.1