Merge pull request #3659 from rtfeldman/when-on-128bit-numbers

when on 128-bit numbers
This commit is contained in:
Ayaz 2022-07-29 14:54:16 -05:00 committed by GitHub
commit fffe9ca8ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 3 deletions

View File

@ -1387,8 +1387,6 @@ fn test_to_equality<'a>(
}
Test::IsInt(test_int, precision) => {
// TODO don't downcast i128 here
debug_assert!(i128::from_ne_bytes(test_int) <= i64::MAX as i128);
let lhs = Expr::Literal(Literal::Int(test_int));
let lhs_symbol = env.unique_symbol();
stores.push((lhs_symbol, Layout::int_width(precision), lhs));

View File

@ -8957,7 +8957,7 @@ impl NumLiteral {
fn to_pattern(&self) -> Pattern<'static> {
match *self {
NumLiteral::Int(n, w) => Pattern::IntLiteral(n, w),
NumLiteral::U128(_) => todo!(),
NumLiteral::U128(n) => Pattern::IntLiteral(n, IntWidth::U128),
NumLiteral::Float(n, w) => Pattern::FloatLiteral(f64::to_bits(n), w),
NumLiteral::Decimal(n) => Pattern::DecimalLiteral(n),
}

View File

@ -3679,3 +3679,39 @@ fn when_on_decimals() {
i64
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn when_on_i128() {
assert_evals_to!(
indoc!(
r#"
when 1701411834604692317316873037158841057i128 is
1701411834604692317316873037158841057 -> 42
32 -> 1
64 -> 2
_ -> 4
"#
),
42,
i64
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn when_on_u128() {
assert_evals_to!(
indoc!(
r#"
when 170141183460469231731687303715884105728u128 is
170141183460469231731687303715884105728u128 -> 42
32 -> 1
64 -> 2
_ -> 4
"#
),
42,
i64
);
}