Sema: fix enum value without tag name used as switch item

Previously stage2 would report a false positive compile error saying there
was no tag for this value.
This commit is contained in:
Andrew Kelley
2022-07-19 18:39:48 -07:00
parent 1d5f865cfa
commit 0efc6a35be
2 changed files with 27 additions and 19 deletions

View File

@@ -672,3 +672,21 @@ test "capture of integer forwards the switch condition directly" {
comptime try S.foo(42);
comptime try S.foo(100);
}
test "enum value without tag name used as switch item" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
const E = enum(u32) {
a = 1,
b = 2,
_,
};
var e: E = @intToEnum(E, 0);
switch (e) {
@intToEnum(E, 0) => {},
.a => return error.TestFailed,
.b => return error.TestFailed,
_ => return error.TestFailed,
}
}