From 0efc6a35bead74b5faffbc87b446b5087f1bb99b Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 19 Jul 2022 18:39:48 -0700 Subject: 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. --- test/behavior/switch.zig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test') diff --git a/test/behavior/switch.zig b/test/behavior/switch.zig index c44f8fe223..3a49c03b18 100644 --- a/test/behavior/switch.zig +++ b/test/behavior/switch.zig @@ -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, + } +} -- cgit v1.2.3