aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-08-25 11:42:19 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-08-25 11:42:19 -0400
commit8f41da221690a8dbbbce41a07513715b9a31e70a (patch)
treee51906aa865ac2041806aac18f4f66da06caefed /src/analyze.cpp
parentfa6c20a02d2ee7648f69d9ba3b19fa600e8dd0e9 (diff)
downloadzig-8f41da221690a8dbbbce41a07513715b9a31e70a.tar.gz
zig-8f41da221690a8dbbbce41a07513715b9a31e70a.zip
fix behavior test regressions with unions
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 7c967b4e5c..5e0abea5df 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -1950,6 +1950,12 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) {
}
} else if (packed) {
field->align = 1;
+ } else if (field->type_entry != nullptr) {
+ if ((err = type_resolve(g, field->type_entry, ResolveStatusAlignmentKnown))) {
+ union_type->data.unionation.resolve_status = ResolveStatusInvalid;
+ return err;
+ }
+ field->align = field->type_entry->abi_align;
} else {
if ((err = type_val_resolve_abi_align(g, field->type_val, &field->align))) {
union_type->data.unionation.resolve_status = ResolveStatusInvalid;
@@ -2040,12 +2046,14 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
AstNode *field_source_node = decl_node->data.container_decl.fields.at(i);
TypeUnionField *union_field = &union_type->data.unionation.fields[i];
- if ((err = ir_resolve_lazy(g, field_source_node, union_field->type_val))) {
- union_type->data.unionation.resolve_status = ResolveStatusInvalid;
- return err;
+ if (union_field->type_entry == nullptr) {
+ if ((err = ir_resolve_lazy(g, field_source_node, union_field->type_val))) {
+ union_type->data.unionation.resolve_status = ResolveStatusInvalid;
+ return err;
+ }
+ union_field->type_entry = union_field->type_val->data.x_type;
}
- ZigType *field_type = union_field->type_val->data.x_type;
- union_field->type_entry = field_type;
+ ZigType *field_type = union_field->type_entry;
if ((err = type_resolve(g, field_type, ResolveStatusSizeKnown))) {
union_type->data.unionation.resolve_status = ResolveStatusInvalid;
@@ -4999,7 +5007,11 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
case ZigTypeIdUnion:
if (type_entry->data.unionation.src_field_count > 1)
return OnePossibleValueNo;
- return type_has_one_possible_value(g, type_entry->data.unionation.fields[0].type_entry);
+ TypeUnionField *only_field = &type_entry->data.unionation.fields[0];
+ if (only_field->type_entry != nullptr) {
+ return type_has_one_possible_value(g, only_field->type_entry);
+ }
+ return type_val_resolve_has_one_possible_value(g, only_field->type_val);
}
zig_unreachable();
}