Permit explicit tags with '_' switch prong
Mainly affects ZIR representation of switch_block[_ref] and special prong (detection) logic for switch. Adds a new SpecialProng tag 'absorbing_under' that allows specifying additional explicit tags in a '_' prong which are respected when checking that every value is handled during semantic analysis but are not transformed into AIR and instead 'absorbed' by the '_' branch.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
const E = enum(u8) {
|
||||
a,
|
||||
b,
|
||||
_,
|
||||
};
|
||||
const U = union(E) {
|
||||
a: i32,
|
||||
b: u32,
|
||||
};
|
||||
pub export fn entry1() void {
|
||||
const e: E = .b;
|
||||
switch (e) { // error: switch not handling the tag `b`
|
||||
.a, _ => {},
|
||||
}
|
||||
}
|
||||
pub export fn entry2() void {
|
||||
const u = U{ .a = 2 };
|
||||
switch (u) { // error: `_` prong not allowed when switching on tagged union
|
||||
.a => {},
|
||||
.b, _ => {},
|
||||
}
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :12:5: error: switch must handle all possibilities
|
||||
// :3:5: note: unhandled enumeration value: 'b'
|
||||
// :1:11: note: enum 'tmp.E' declared here
|
||||
// :18:5: error: '_' prong only allowed when switching on non-exhaustive enums
|
||||
// :20:13: note: '_' prong here
|
||||
// :18:5: note: consider using 'else'
|
||||
@@ -16,5 +16,5 @@ pub export fn entry() void {
|
||||
// target=native
|
||||
//
|
||||
// :7:5: error: '_' prong only allowed when switching on non-exhaustive enums
|
||||
// :10:11: note: '_' prong here
|
||||
// :10:9: note: '_' prong here
|
||||
// :7:5: note: consider using 'else'
|
||||
|
||||
@@ -39,5 +39,5 @@ pub export fn entry3() void {
|
||||
// :1:11: note: enum 'tmp.E' declared here
|
||||
// :19:5: error: switch on non-exhaustive enum must include 'else' or '_' prong
|
||||
// :26:5: error: '_' prong only allowed when switching on non-exhaustive enums
|
||||
// :29:11: note: '_' prong here
|
||||
// :29:9: note: '_' prong here
|
||||
// :26:5: note: consider using 'else'
|
||||
|
||||
Reference in New Issue
Block a user