diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-12-05 20:46:58 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-12-05 20:46:58 -0500 |
| commit | 960914a073c367883c9fdf54e900890a6aefc05f (patch) | |
| tree | 4dca5efa7967f0ecca20bd0d852005008a1ec925 /src/codegen.cpp | |
| parent | 63a2f9a8b2251ffdc37d5f28dfbd3f6be1bd7908 (diff) | |
| download | zig-960914a073c367883c9fdf54e900890a6aefc05f.tar.gz zig-960914a073c367883c9fdf54e900890a6aefc05f.zip | |
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
Diffstat (limited to 'src/codegen.cpp')
| -rw-r--r-- | src/codegen.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
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); |
