diff options
Diffstat (limited to 'test/compile_errors.zig')
| -rw-r--r-- | test/compile_errors.zig | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 6c123925da..0b9c754329 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -51,6 +51,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "tmp.zig:17:23: error: cannot adjust alignment of zero sized type 'fn(u32) anytype'", }); + cases.addTest("invalid non-exhaustive enum to union", + \\const E = enum(u8) { + \\ a, + \\ b, + \\ _, + \\}; + \\const U = union(E) { + \\ a, + \\ b, + \\}; + \\export fn foo() void { + \\ var e = @intToEnum(E, 15); + \\ var u: U = e; + \\} + \\export fn bar() void { + \\ const e = @intToEnum(E, 15); + \\ var u: U = e; + \\} + , &[_][]const u8{ + "tmp.zig:12:16: error: runtime cast to union 'U' from non-exhustive enum", + "tmp.zig:16:16: error: no tag by value 15", + }); + cases.addTest("switching with exhaustive enum has '_' prong ", \\const E = enum{ \\ a, |
