aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorkkHAIKE <kkhaike@gmail.com>2022-09-27 18:23:51 +0800
committerGitHub <noreply@github.com>2022-09-27 13:23:51 +0300
commitba5cbea0c3c6ee2e22606365edde18342fcf0579 (patch)
tree1c3f9c6581391abd525ac54bf55b40ccc8fcfe1a /test
parentf7f15e99c418ab0efac268e9087ce45d55744edc (diff)
downloadzig-ba5cbea0c3c6ee2e22606365edde18342fcf0579.tar.gz
zig-ba5cbea0c3c6ee2e22606365edde18342fcf0579.zip
Sema: fix segfault when union init with empty field
Diffstat (limited to 'test')
-rw-r--r--test/cases/compile_errors/union_init_with_none_or_multiple_fields.zig37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/cases/compile_errors/union_init_with_none_or_multiple_fields.zig b/test/cases/compile_errors/union_init_with_none_or_multiple_fields.zig
new file mode 100644
index 0000000000..5f486bf2b7
--- /dev/null
+++ b/test/cases/compile_errors/union_init_with_none_or_multiple_fields.zig
@@ -0,0 +1,37 @@
+const U1 = union {
+ a: u8,
+ b: i8,
+};
+const U2 = union(enum) {
+ a: u8,
+ b: i8,
+};
+export fn u1z() void {
+ const x: U1 = .{};
+ _ = x;
+}
+export fn u1m() void {
+ const x: U1 = .{ .a = 1, .b = 1 };
+ _ = x;
+}
+export fn u2z() void {
+ const x: U2 = U2{};
+ _ = x;
+}
+export fn u2m() void {
+ const x: U2 = .{ .a = 1, .b = 1 };
+ _ = x;
+}
+
+// error
+// backend=stage2
+// target=native
+//
+// :9:1: error: union initializer must initialize one field
+// :14:20: error: cannot initialize multiple union fields at once, unions can only have one active field
+// :14:31: note: additional initializer here
+// :18:21: error: union initializer must initialize one field
+// :22:20: error: cannot initialize multiple union fields at once, unions can only have one active field
+// :22:31: note: additional initializer here
+// :1:12: note: union declared here
+// :5:12: note: union declared here