Emit decimal AIR patterns without source suffixes, radix spellings or separators. Validate range before formatting and preserve duplicate-value detection, including negative zero and 128-bit boundaries. Add source run/reject regressions for canonical spelling, duplicates and out-of-range patterns; clarify the existing integer pattern contract.
21 lines
857 B
Rust
21 lines
857 B
Rust
// expect: run
|
|
// result: 42
|
|
// phase: 6
|
|
// spec: docs/spec/15-source-language.md §6; docs/spec/07-air.md §8.5
|
|
module test.integer_patterns
|
|
fn unsigned(value: u64) -> u64 effects [] {
|
|
return match value { 0x2_au64 => { 42u64 }, 0u64 => { 0u64 }, _ => { 99u64 } };
|
|
}
|
|
fn signed(value: i64) -> u64 effects [] {
|
|
return match value { -0x2ai64 => { 42u64 }, -0i64 => { 0u64 }, _ => { 99u64 } };
|
|
}
|
|
fn main() -> u64 effects [] {
|
|
assert(unsigned(42u64) == 42u64); assert(unsigned(0u64) == 0u64);
|
|
assert(signed(-42i64) == 42u64); assert(signed(0i64) == 0u64);
|
|
let maximum = 340282366920938463463374607431768211455u128;
|
|
match maximum { 0xffffffffffffffffffffffffffffffffu128 => {}, _ => { trap; } }
|
|
let minimum = -170141183460469231731687303715884105728i128;
|
|
match minimum { -170141183460469231731687303715884105728i128 => {}, _ => { trap; } }
|
|
return 42;
|
|
}
|