diff options
| author | Jimmi Holst Christensen <jhc@liab.dk> | 2018-03-08 10:29:43 +0100 |
|---|---|---|
| committer | Jimmi Holst Christensen <jhc@liab.dk> | 2018-03-08 10:29:43 +0100 |
| commit | 689e241ff8a826ac03cca0e8d1c9f8628cc88756 (patch) | |
| tree | 8e09e8995ccec56f2f858d340b824b24733a578d /src | |
| parent | 51b2f1b80b9bc43dc389044565cc3a72c174311e (diff) | |
| parent | 790aaeacaea88782987c4145bc7ae47a401563f1 (diff) | |
| download | zig-689e241ff8a826ac03cca0e8d1c9f8628cc88756.tar.gz zig-689e241ff8a826ac03cca0e8d1c9f8628cc88756.zip | |
Merge branch 'master' of github.com:zig-lang/zig
Diffstat (limited to 'src')
| -rw-r--r-- | src/all_types.hpp | 2 | ||||
| -rw-r--r-- | src/analyze.cpp | 2 | ||||
| -rw-r--r-- | src/ir.cpp | 8 |
3 files changed, 12 insertions, 0 deletions
diff --git a/src/all_types.hpp b/src/all_types.hpp index 6f36d34bfd..3d732d4ace 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1096,6 +1096,8 @@ struct TypeTableEntryUnion { size_t gen_union_index; size_t gen_tag_index; + bool have_explicit_tag_type; + uint32_t union_size_bytes; TypeTableEntry *most_aligned_union_member; diff --git a/src/analyze.cpp b/src/analyze.cpp index 66d2963425..74dfd003d9 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -2558,6 +2558,8 @@ static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) { HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> occupied_tag_values = {}; AstNode *enum_type_node = decl_node->data.container_decl.init_arg_expr; + union_type->data.unionation.have_explicit_tag_type = decl_node->data.container_decl.auto_enum || + enum_type_node != nullptr; bool auto_layout = (union_type->data.unionation.layout == ContainerLayoutAuto); bool want_safety = (field_count >= 2) && (auto_layout || enum_type_node != nullptr); TypeTableEntry *tag_type; diff --git a/src/ir.cpp b/src/ir.cpp index cdb8201b2b..811744e9d0 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -14137,6 +14137,14 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value.type->name))); return ira->codegen->invalid_instruction; } + if (!value->value.type->data.unionation.have_explicit_tag_type && !source_instr->is_gen) { + ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union has no associated enum")); + if (value->value.type->data.unionation.decl_node != nullptr) { + add_error_note(ira->codegen, msg, value->value.type->data.unionation.decl_node, + buf_sprintf("declared here")); + } + return ira->codegen->invalid_instruction; + } TypeTableEntry *tag_type = value->value.type->data.unionation.tag_type; assert(tag_type->id == TypeTableEntryIdEnum); |
