| 1 | const E = enum(u8) { |
| 2 | a, |
| 3 | b, |
| 4 | _, |
| 5 | }; |
| 6 | const U = union(E) { |
| 7 | a: i32, |
| 8 | b: u32, |
| 9 | }; |
| 10 | pub export fn entry1() void { |
| 11 | const e: E = .b; |
| 12 | switch (e) { // error: switch not handling the tag `b` |
| 13 | .a => {}, |
| 14 | _ => {}, |
| 15 | } |
| 16 | } |
| 17 | pub export fn entry2() void { |
| 18 | const e: E = .b; |
| 19 | switch (e) { // error: switch on non-exhaustive enum must include `else` or `_` prong |
| 20 | .a => {}, |
| 21 | .b => {}, |
| 22 | } |
| 23 | } |
| 24 | pub export fn entry3() void { |
| 25 | const u = U{ .a = 2 }; |
| 26 | switch (u) { // error: `_` prong not allowed when switching on tagged union |
| 27 | .a => {}, |
| 28 | .b => {}, |
| 29 | _ => {}, |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | // error |
| 34 | // |
| 35 | // :12:5: error: switch must handle all possibilities |
| 36 | // :3:5: note: unhandled enumeration value: 'b' |
| 37 | // :1:11: note: enum 'tmp.E' declared here |
| 38 | // :19:5: error: switch on non-exhaustive enum must include 'else' or '_' prong or both |
| 39 | // :26:5: error: '_' prong only allowed when switching on non-exhaustive enums |
| 40 | // :29:9: note: '_' prong here |
| 41 | // :26:5: note: consider using 'else' |