aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-09-14 00:37:54 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-09-14 00:38:22 -0400
commit3d38feded93cb2ccecf5ecb538c8957a965a891e (patch)
tree280a01fb2c02360887e83b43e4a78c1feca0cac9
parent1e03cf1739c9c7407c4b3a56ee5f2705805c6a83 (diff)
downloadzig-3d38feded93cb2ccecf5ecb538c8957a965a891e.tar.gz
zig-3d38feded93cb2ccecf5ecb538c8957a965a891e.zip
fix tagged union with all void payloads but meaningful tag
closes #1322
-rw-r--r--src/codegen.cpp2
-rw-r--r--test/behavior.zig1
-rw-r--r--test/cases/bugs/1322.zig19
3 files changed, 21 insertions, 1 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index d7d7223657..98bb06e6ee 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -4715,7 +4715,6 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executa
static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, IrInstructionUnionTag *instruction) {
ZigType *union_type = instruction->value->value.type;
- assert(union_type->data.unionation.gen_tag_index != SIZE_MAX);
ZigType *tag_type = union_type->data.unionation.tag_type;
if (!type_has_bits(tag_type))
@@ -4725,6 +4724,7 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, Ir
if (union_type->data.unionation.gen_field_count == 0)
return union_val;
+ assert(union_type->data.unionation.gen_tag_index != SIZE_MAX);
LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, union_val,
union_type->data.unionation.gen_tag_index, "");
ZigType *ptr_type = get_pointer_to_type(g, tag_type, false);
diff --git a/test/behavior.zig b/test/behavior.zig
index 869024f296..3223131d08 100644
--- a/test/behavior.zig
+++ b/test/behavior.zig
@@ -10,6 +10,7 @@ comptime {
_ = @import("cases/bool.zig");
_ = @import("cases/bugs/1111.zig");
_ = @import("cases/bugs/1277.zig");
+ _ = @import("cases/bugs/1322.zig");
_ = @import("cases/bugs/1381.zig");
_ = @import("cases/bugs/1421.zig");
_ = @import("cases/bugs/1442.zig");
diff --git a/test/cases/bugs/1322.zig b/test/cases/bugs/1322.zig
new file mode 100644
index 0000000000..2de92191ec
--- /dev/null
+++ b/test/cases/bugs/1322.zig
@@ -0,0 +1,19 @@
+const std = @import("std");
+
+const B = union(enum) {
+ c: C,
+ None,
+};
+
+const A = struct {
+ b: B,
+};
+
+const C = struct {};
+
+test "tagged union with all void fields but a meaningful tag" {
+ var a: A = A{ .b = B{ .c = C{} } };
+ std.debug.assert(@TagType(B)(a.b) == @TagType(B).c);
+ a = A{ .b = B.None };
+ std.debug.assert(@TagType(B)(a.b) == @TagType(B).None);
+}