2022-03-24 05:28:08 +00:00
|
|
|
const E = enum(u8) {
|
|
|
|
a,
|
|
|
|
b,
|
|
|
|
_,
|
|
|
|
};
|
|
|
|
const U = union(E) {
|
|
|
|
a: i32,
|
|
|
|
b: u32,
|
|
|
|
};
|
2022-07-12 11:52:39 +01:00
|
|
|
pub export fn entry1() void {
|
2022-03-24 05:28:08 +00:00
|
|
|
var e: E = .b;
|
|
|
|
switch (e) { // error: switch not handling the tag `b`
|
|
|
|
.a => {},
|
|
|
|
_ => {},
|
|
|
|
}
|
2022-07-12 11:52:39 +01:00
|
|
|
}
|
|
|
|
pub export fn entry2() void {
|
|
|
|
var e: E = .b;
|
2022-03-24 05:28:08 +00:00
|
|
|
switch (e) { // error: switch on non-exhaustive enum must include `else` or `_` prong
|
|
|
|
.a => {},
|
|
|
|
.b => {},
|
|
|
|
}
|
2022-07-12 11:52:39 +01:00
|
|
|
}
|
|
|
|
pub export fn entry3() void {
|
2022-03-24 05:28:08 +00:00
|
|
|
var u = U{.a = 2};
|
|
|
|
switch (u) { // error: `_` prong not allowed when switching on tagged union
|
|
|
|
.a => {},
|
|
|
|
.b => {},
|
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-28 13:44:34 +01:00
|
|
|
// error
|
2022-07-12 11:52:39 +01:00
|
|
|
// backend=stage2
|
2022-04-28 13:44:34 +01:00
|
|
|
// target=native
|
2022-03-24 05:28:08 +00:00
|
|
|
//
|
2022-07-12 11:52:39 +01:00
|
|
|
// :12:5: error: switch must handle all possibilities
|
2022-07-18 23:25:10 +01:00
|
|
|
// :3:5: note: unhandled enumeration value: 'b'
|
2022-07-12 11:52:39 +01:00
|
|
|
// :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
|