Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion crates/jett_comptime/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8707,7 +8707,14 @@ impl Interpreter {
let mut total: i64 = 0;
for item in items {
match item {
Value::Int64(n) => total += n,
Value::Int64(n) => {
let Some(next_total) = total.checked_add(*n) else {
return Some(Err(format!(
"math.sum: integer overflow: {total} + {n}"
)));
};
total = next_total;
}
_ => {
return Some(Err(
"math.sum: list must contain int64 values".to_string()
Expand Down
8 changes: 8 additions & 0 deletions crates/jett_driver/tests/fixture_suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,14 @@ fn sized_integer_runtime_bounds_reject_variable_arithmetic() {
}
}

#[test]
fn math_sum_reports_overflow() {
assert_runtime_fail(
"math_sum_overflow.jett",
"runtime error: math.sum: integer overflow: 9223372036854775807 + 1",
);
}

#[test]
fn run_file_capture_stdout_captures_json_runtime_output() {
assert_run_stdout(
Expand Down
4 changes: 4 additions & 0 deletions tests/runtime_fail/math_sum_overflow.jett
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function main() returns nothing:
int64 maximum = 9223372036854775807
int64 total = math.sum(list(maximum, 1))
return nothing