authorgravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2018-03-08 10:29:43+01:00
committergravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2018-03-08 10:29:43+01:00
log689e241ff8a826ac03cca0e8d1c9f8628cc88756
tree8e09e8995ccec56f2f858d340b824b24733a578d
parent51b2f1b80b9bc43dc389044565cc3a72c174311e
parent790aaeacaea88782987c4145bc7ae47a401563f1

Merge branch 'master' of github.com:zig-lang/zig


4 files changed, 25 insertions(+), 0 deletions(-)

src/all_types.hpp+2
......@@ -1096,6 +1096,8 @@ struct TypeTableEntryUnion {
10961096 size_t gen_union_index;
10971097 size_t gen_tag_index;
10981098
1099 bool have_explicit_tag_type;
1100
10991101 uint32_t union_size_bytes;
11001102 TypeTableEntry *most_aligned_union_member;
11011103
src/analyze.cpp+2
......@@ -2558,6 +2558,8 @@ static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
25582558 HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> occupied_tag_values = {};
25592559
25602560 AstNode *enum_type_node = decl_node->data.container_decl.init_arg_expr;
2561 union_type->data.unionation.have_explicit_tag_type = decl_node->data.container_decl.auto_enum ||
2562 enum_type_node != nullptr;
25612563 bool auto_layout = (union_type->data.unionation.layout == ContainerLayoutAuto);
25622564 bool want_safety = (field_count >= 2) && (auto_layout || enum_type_node != nullptr);
25632565 TypeTableEntry *tag_type;
src/ir.cpp+8
......@@ -14137,6 +14137,14 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
1413714137 buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value.type->name)));
1413814138 return ira->codegen->invalid_instruction;
1413914139 }
14140 if (!value->value.type->data.unionation.have_explicit_tag_type && !source_instr->is_gen) {
14141 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union has no associated enum"));
14142 if (value->value.type->data.unionation.decl_node != nullptr) {
14143 add_error_note(ira->codegen, msg, value->value.type->data.unionation.decl_node,
14144 buf_sprintf("declared here"));
14145 }
14146 return ira->codegen->invalid_instruction;
14147 }
1414014148
1414114149 TypeTableEntry *tag_type = value->value.type->data.unionation.tag_type;
1414214150 assert(tag_type->id == TypeTableEntryIdEnum);
test/compile_errors.zig+13
......@@ -1,6 +1,19 @@
11const tests = @import("tests.zig");
22
33pub fn addCases(cases: &tests.CompileErrorContext) void {
4 cases.add("@tagName used on union with no associated enum tag",
5 \\const FloatInt = extern union {
6 \\ Float: f32,
7 \\ Int: i32,
8 \\};
9 \\export fn entry() void {
10 \\ var fi = FloatInt{.Float = 123.45};
11 \\ var tagName = @tagName(fi);
12 \\}
13 ,
14 ".tmp_source.zig:7:19: error: union has no associated enum",
15 ".tmp_source.zig:1:18: note: declared here");
16
417 cases.add("returning error from void async function",
518 \\const std = @import("std");
619 \\export fn entry() void {