cli: canonicalize integer match patterns
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.
This commit is contained in:
1 parent
1eaf968f4f
commit
fc23f1b23a
6 files changed
+51
-2
No files matched your search
@@ -0,0 +1,7 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §6
|
||||
module test.integer_patterns
|
||||
fn main() -> u64 effects [] {
|
||||
return match 42u64 { 42u64 => { 42u64 }, 0x2_au64 => { 0u64 }, _ => { 99u64 } };
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/07a-air-instructions.md switch.I; docs/spec/15-source-language.md §6
|
||||
module test.integer_patterns
|
||||
fn main() -> u64 effects [] {
|
||||
return match 0u8 { 256 => { 42u64 }, _ => { 0u64 } };
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// 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;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §6
|
||||
module test.integer_patterns
|
||||
fn main() -> u64 effects [] {
|
||||
return match 0u8 { -1 => { 42u64 }, _ => { 0u64 } };
|
||||
}
|
||||
Reference in new issue
Block a user