aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-09-05 16:19:58 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-09-05 16:19:58 -0400
commitffb3b1576b1c02942bce89ef05eaf05fe2f026ac (patch)
treef2dc8e6f831f0bafab2f27d475d2d29e6a557fb1
parentc87a576cb5afaf54e68bae10119305af71aaa3a1 (diff)
downloadzig-ffb3b1576b1c02942bce89ef05eaf05fe2f026ac.tar.gz
zig-ffb3b1576b1c02942bce89ef05eaf05fe2f026ac.zip
stage1: fix tagged union with no payloads
closes #1478
-rw-r--r--src/codegen.cpp2
-rw-r--r--test/cases/union.zig13
2 files changed, 14 insertions, 1 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 2f7a25cf93..f5c1019892 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -5490,7 +5490,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
LLVMTypeRef union_type_ref = type_entry->data.unionation.union_type_ref;
if (type_entry->data.unionation.gen_field_count == 0) {
- if (type_entry->data.unionation.gen_tag_index == SIZE_MAX) {
+ if (type_entry->data.unionation.tag_type == nullptr) {
return nullptr;
} else {
return bigint_to_llvm_const(type_entry->data.unionation.tag_type->type_ref,
diff --git a/test/cases/union.zig b/test/cases/union.zig
index 08969e64fe..0c55fb92e7 100644
--- a/test/cases/union.zig
+++ b/test/cases/union.zig
@@ -311,3 +311,16 @@ fn testTaggedUnionInit(x: var) bool {
const y = TaggedUnionWithAVoid{ .A = x };
return @TagType(TaggedUnionWithAVoid)(y) == TaggedUnionWithAVoid.A;
}
+
+pub const UnionEnumNoPayloads = union(enum) {
+ A,
+ B,
+};
+
+test "tagged union with no payloads" {
+ const a = UnionEnumNoPayloads{ .B = {} };
+ switch (a) {
+ @TagType(UnionEnumNoPayloads).A => @panic("wrong"),
+ @TagType(UnionEnumNoPayloads).B => {},
+ }
+}