stage1: fix tagged union with no payloads

closes #1478
This commit is contained in:
Andrew Kelley 2018-09-05 16:19:58 -04:00
parent c87a576cb5
commit ffb3b1576b
No known key found for this signature in database
GPG Key ID: 4E7CD66038A4D47C
2 changed files with 14 additions and 1 deletions

View File

@ -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,

View File

@ -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 => {},
}
}