about summary refs log tree commit diff
path: root/tvix/eval/src/compiler/mod.rs
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2022-09-18T16·06-0400
committergrfn <grfn@gws.fyi>2022-09-18T16·40+0000
commitd431aa7743f0956cd31ab64b73bbee469783ba51 (patch)
tree133cd7ecc6a6277437c2c939b8d10e8ce62b03d4 /tvix/eval/src/compiler/mod.rs
parentb3cc4c8c2c25008699323491ee2456bd317efeac (diff)
fix(tvix/eval): Emit errors for invalid integers r/4898
Invalid integers (eg integers that're too long) end up as error returns
on the `.value()` returned from the literal in the AST - previously we'd
unwrap this error, causing it to panic the compiler, but now we've got a
nice error variant for it (which just unwraps the underlying
std::num::ParseIntError).

Change-Id: I50c3c5ba89407d86659e20d8991b9658415f39a0
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6635
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src/compiler/mod.rs')
-rw-r--r--tvix/eval/src/compiler/mod.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs
index 52b6e8e542..4d6728b6d6 100644
--- a/tvix/eval/src/compiler/mod.rs
+++ b/tvix/eval/src/compiler/mod.rs
@@ -192,7 +192,10 @@ impl Compiler<'_, '_> {
     fn compile_literal(&mut self, node: ast::Literal) {
         let value = match node.kind() {
             ast::LiteralKind::Float(f) => Value::Float(f.value().unwrap()),
-            ast::LiteralKind::Integer(i) => Value::Integer(i.value().unwrap()),
+            ast::LiteralKind::Integer(i) => match i.value() {
+                Ok(v) => Value::Integer(v),
+                Err(err) => return self.emit_error(&node, err.into()),
+            },
 
             ast::LiteralKind::Uri(u) => {
                 self.emit_warning(&node, WarningKind::DeprecatedLiteralURL);