From 960914a073c367883c9fdf54e900890a6aefc05f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 5 Dec 2017 20:46:58 -0500 Subject: add implicit cast from enum to union when the enum is the tag type of the union and is comptime known to be of a void field of the union See #642 --- src/codegen.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/codegen.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index 35974a73dd..9941238f8f 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3946,8 +3946,6 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { case TypeTableEntryIdUnion: { LLVMTypeRef union_type_ref = type_entry->data.unionation.union_type_ref; - ConstExprValue *payload_value = const_val->data.x_union.payload; - assert(payload_value != nullptr); if (type_entry->data.unionation.gen_field_count == 0) { if (type_entry->data.unionation.gen_tag_index == SIZE_MAX) { @@ -3960,7 +3958,8 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) { LLVMValueRef union_value_ref; bool make_unnamed_struct; - if (!type_has_bits(payload_value->type)) { + ConstExprValue *payload_value = const_val->data.x_union.payload; + if (payload_value == nullptr || !type_has_bits(payload_value->type)) { if (type_entry->data.unionation.gen_tag_index == SIZE_MAX) return LLVMGetUndef(type_entry->type_ref); -- cgit v1.2.3