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
signaturelock-open 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) {...@@ -1950,6 +1950,12 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) {
1950 }1950 }
1951 } else if (packed) {1951 } else if (packed) {
1952 field->align = 1;1952 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;
1953 } else {1959 } else {
1954 if ((err = type_val_resolve_abi_align(g, field->type_val, &field->align))) {1960 if ((err = type_val_resolve_abi_align(g, field->type_val, &field->align))) {
1955 union_type->data.unionation.resolve_status = ResolveStatusInvalid;1961 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
...@@ -2040,12 +2046,14 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {...@@ -2040,12 +2046,14 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
2040 AstNode *field_source_node = decl_node->data.container_decl.fields.at(i);2046 AstNode *field_source_node = decl_node->data.container_decl.fields.at(i);
2041 TypeUnionField *union_field = &union_type->data.unionation.fields[i];2047 TypeUnionField *union_field = &union_type->data.unionation.fields[i];
20422048
2043 if ((err = ir_resolve_lazy(g, field_source_node, union_field->type_val))) {2049 if (union_field->type_entry == nullptr) {
2044 union_type->data.unionation.resolve_status = ResolveStatusInvalid;2050 if ((err = ir_resolve_lazy(g, field_source_node, union_field->type_val))) {
2045 return err;2051 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
2052 return err;
2053 }
2054 union_field->type_entry = union_field->type_val->data.x_type;
2046 }2055 }
2047 ZigType *field_type = union_field->type_val->data.x_type;2056 ZigType *field_type = union_field->type_entry;
2048 union_field->type_entry = field_type;
20492057
2050 if ((err = type_resolve(g, field_type, ResolveStatusSizeKnown))) {2058 if ((err = type_resolve(g, field_type, ResolveStatusSizeKnown))) {
2051 union_type->data.unionation.resolve_status = ResolveStatusInvalid;2059 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
...@@ -4999,7 +5007,11 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {...@@ -4999,7 +5007,11 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
4999 case ZigTypeIdUnion:5007 case ZigTypeIdUnion:
5000 if (type_entry->data.unionation.src_field_count > 1)5008 if (type_entry->data.unionation.src_field_count > 1)
5001 return OnePossibleValueNo;5009 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);
5003 }5015 }
5004 zig_unreachable();5016 zig_unreachable();
5005}5017}