about summary refs log tree commit diff
path: root/tvix/eval/src/vm.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/vm.rs')
-rw-r--r--tvix/eval/src/vm.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs
index 8c45ee7363..127d9bfa51 100644
--- a/tvix/eval/src/vm.rs
+++ b/tvix/eval/src/vm.rs
@@ -412,7 +412,20 @@ impl<'o> VM<'o> {
 
             OpCode::OpSub => arithmetic_op!(self, -),
             OpCode::OpMul => arithmetic_op!(self, *),
-            OpCode::OpDiv => arithmetic_op!(self, /),
+            OpCode::OpDiv => {
+                let b = self.peek(0);
+
+                match b {
+                    Value::Integer(0) => return Err(self.error(ErrorKind::DivisionByZero)),
+                    Value::Float(b) => {
+                        if *b == (0.0 as f64) {
+                            return Err(self.error(ErrorKind::DivisionByZero));
+                        }
+                        arithmetic_op!(self, /)
+                    }
+                    _ => arithmetic_op!(self, /),
+                };
+            }
 
             OpCode::OpInvert => {
                 let v = fallible!(self, self.pop().as_bool());