authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-05 16:19:58-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-05 16:19:58-04:00
logffb3b1576b1c02942bce89ef05eaf05fe2f026ac
treef2dc8e6f831f0bafab2f27d475d2d29e6a557fb1
parentc87a576cb5afaf54e68bae10119305af71aaa3a1
signaturelock-open Commit is signed but in an unrecognized format.

stage1: fix tagged union with no payloads

closes #1478

2 files changed, 14 insertions(+), 1 deletions(-)

src/codegen.cpp+1-1
......@@ -5490,7 +5490,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
54905490 LLVMTypeRef union_type_ref = type_entry->data.unionation.union_type_ref;
54915491
54925492 if (type_entry->data.unionation.gen_field_count == 0) {
5493 if (type_entry->data.unionation.gen_tag_index == SIZE_MAX) {
5493 if (type_entry->data.unionation.tag_type == nullptr) {
54945494 return nullptr;
54955495 } else {
54965496 return bigint_to_llvm_const(type_entry->data.unionation.tag_type->type_ref,
test/cases/union.zig+13
......@@ -311,3 +311,16 @@ fn testTaggedUnionInit(x: var) bool {
311311 const y = TaggedUnionWithAVoid{ .A = x };
312312 return @TagType(TaggedUnionWithAVoid)(y) == TaggedUnionWithAVoid.A;
313313}
314
315pub const UnionEnumNoPayloads = union(enum) {
316 A,
317 B,
318};
319
320test "tagged union with no payloads" {
321 const a = UnionEnumNoPayloads{ .B = {} };
322 switch (a) {
323 @TagType(UnionEnumNoPayloads).A => @panic("wrong"),
324 @TagType(UnionEnumNoPayloads).B => {},
325 }
326}