fix List.range so that it will only crash when Length is too large

This commit is contained in:
Brendan Hansknecht 2023-02-27 16:01:05 -08:00
parent bcaff7f478
commit f77d1dcd6b
No known key found for this signature in database
GPG key ID: A199D0660F95F948
2 changed files with 70 additions and 24 deletions

View file

@ -3696,6 +3696,24 @@ fn list_walk_from_even_prefix_sum() {
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
// TODO: update how roc decides whether or not to print `User crashed` or `Roc failed` such that this prints `Roc failed ...``
#[should_panic(
expected = r#"User crash with message: "List.range: failed to generate enough elements to fill the range before overflowing the numeric type"#
)]
fn list_range_length_overflow() {
assert_evals_to!(
indoc!(
r#"
List.range {start: At 255u8, end: Length 2}
"#
),
RocList::default(),
RocList::<u8>
);
}
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
mod pattern_match {
#[cfg(feature = "gen-llvm")]