| ... | ... | @@ -0,0 +1,56 @@ |
| 1 | const E = enum(u8) { |
| 2 | a, |
| 3 | b, |
| 4 | _, |
| 5 | }; |
| 6 | const U = union(E) { |
| 7 | a, |
| 8 | b, |
| 9 | }; |
| 10 | fn foo() U { |
| 11 | return undefined; |
| 12 | } |
| 13 | |
| 14 | export fn entry1() void { |
| 15 | const u = foo(); |
| 16 | switch (u) { |
| 17 | .a => {}, |
| 18 | } |
| 19 | } |
| 20 | export fn entry2() void { |
| 21 | const u = foo(); |
| 22 | switch (u) { |
| 23 | .a => {}, |
| 24 | .b => {}, |
| 25 | else => {}, |
| 26 | } |
| 27 | } |
| 28 | export fn entry3() void { |
| 29 | const u = foo(); |
| 30 | switch (u) { |
| 31 | .a => {}, |
| 32 | .b => {}, |
| 33 | _ => {}, |
| 34 | } |
| 35 | } |
| 36 | export fn entry4() void { |
| 37 | const u = foo(); |
| 38 | switch (u) { |
| 39 | .a => {}, |
| 40 | else => {}, |
| 41 | _ => {}, |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | // error |
| 46 | // |
| 47 | // :16:5: error: switch must handle all possibilities |
| 48 | // :3:5: note: unhandled enumeration value: 'b' |
| 49 | // :1:11: note: enum 'tmp.E' declared here |
| 50 | // :25:14: error: unreachable else prong; all cases already handled |
| 51 | // :30:5: error: '_' prong only allowed when switching on non-exhaustive enums |
| 52 | // :33:9: note: '_' prong here |
| 53 | // :30:5: note: consider using 'else' |
| 54 | // :38:5: error: '_' prong only allowed when switching on non-exhaustive enums |
| 55 | // :41:9: note: '_' prong here |
| 56 | // :38:5: note: consider using 'else' |