aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-07-19 18:39:48 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-07-19 18:39:48 -0700
commit0efc6a35bead74b5faffbc87b446b5087f1bb99b (patch)
tree6b8eaabe33a371d366c0be57b76c57e458d963e4 /test
parent1d5f865cfafdaa96cac35ada9bb9e8b1a4e2bc36 (diff)
downloadzig-0efc6a35bead74b5faffbc87b446b5087f1bb99b.tar.gz
zig-0efc6a35bead74b5faffbc87b446b5087f1bb99b.zip
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.
Diffstat (limited to 'test')
-rw-r--r--test/behavior/switch.zig18
1 files changed, 18 insertions, 0 deletions
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,
+ }
+}