add test coverage for type used as switch case

closes #996
This commit is contained in:
Andrew Kelley 2019-02-26 19:41:36 -05:00
parent d5fc826437
commit 763357c9c3
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9

View File

@ -2,6 +2,25 @@ const tests = @import("tests.zig");
const builtin = @import("builtin");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.addTest(
"not an enum type",
\\export fn entry() void {
\\ var self: Error = undefined;
\\ switch (self) {
\\ InvalidToken => |x| return x.token,
\\ ExpectedVarDeclOrFn => |x| return x.token,
\\ }
\\}
\\const Error = union(enum) {
\\ A: InvalidToken,
\\ B: ExpectedVarDeclOrFn,
\\};
\\const InvalidToken = struct {};
\\const ExpectedVarDeclOrFn = struct {};
,
".tmp_source.zig:4:9: error: not an enum type",
);
cases.addTest(
"binary OR operator on error sets",
\\pub const A = error.A;