authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-25 11:42:19-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-25 11:42:19-04:00
log8f41da221690a8dbbbce41a07513715b9a31e70a
treee51906aa865ac2041806aac18f4f66da06caefed
parentfa6c20a02d2ee7648f69d9ba3b19fa600e8dd0e9
signature Commit is signed but in an unrecognized format.

fix behavior test regressions with unions


1 files changed, 18 insertions(+), 6 deletions(-)

src/analyze.cpp+18-6
......@@ -1950,6 +1950,12 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) {
19501950 }
19511951 } else if (packed) {
19521952 field->align = 1;
1953 } else if (field->type_entry != nullptr) {
1954 if ((err = type_resolve(g, field->type_entry, ResolveStatusAlignmentKnown))) {
1955 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
1956 return err;
1957 }
1958 field->align = field->type_entry->abi_align;
19531959 } else {
19541960 if ((err = type_val_resolve_abi_align(g, field->type_val, &field->align))) {
19551961 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
......@@ -2040,12 +2046,14 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
20402046 AstNode *field_source_node = decl_node->data.container_decl.fields.at(i);
20412047 TypeUnionField *union_field = &union_type->data.unionation.fields[i];
20422048
2043 if ((err = ir_resolve_lazy(g, field_source_node, union_field->type_val))) {
2044 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
2045 return err;
2049 if (union_field->type_entry == nullptr) {
2050 if ((err = ir_resolve_lazy(g, field_source_node, union_field->type_val))) {
2051 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
2052 return err;
2053 }
2054 union_field->type_entry = union_field->type_val->data.x_type;
20462055 }
2047 ZigType *field_type = union_field->type_val->data.x_type;
2048 union_field->type_entry = field_type;
2056 ZigType *field_type = union_field->type_entry;
20492057
20502058 if ((err = type_resolve(g, field_type, ResolveStatusSizeKnown))) {
20512059 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
......@@ -4999,7 +5007,11 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
49995007 case ZigTypeIdUnion:
50005008 if (type_entry->data.unionation.src_field_count > 1)
50015009 return OnePossibleValueNo;
5002 return type_has_one_possible_value(g, type_entry->data.unionation.fields[0].type_entry);
5010 TypeUnionField *only_field = &type_entry->data.unionation.fields[0];
5011 if (only_field->type_entry != nullptr) {
5012 return type_has_one_possible_value(g, only_field->type_entry);
5013 }
5014 return type_val_resolve_has_one_possible_value(g, only_field->type_val);
50035015 }
50045016 zig_unreachable();
50055017}