stage1: Force union member types to be resolved

No test case because I couldn't reduce the huuuge test case.
Fixes the problem discovered by @ifreund.
master
LemonBoy 2020-11-25 22:13:40 +01:00 committed by Andrew Kelley
parent 58365c4e79
commit 21c488ce68
1 changed files with 23 additions and 1 deletions

View File

@ -3539,7 +3539,29 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
union_type->abi_size = SIZE_MAX;
union_type->size_in_bits = SIZE_MAX;
}
union_type->data.unionation.resolve_status = zero_bits ? ResolveStatusSizeKnown : ResolveStatusZeroBitsKnown;
if (zero_bits) {
// Don't forget to resolve the types for each union member even though
// the type is zero sized.
// XXX: Do it in a nicer way in stage2.
union_type->data.unionation.resolve_loop_flag_other = true;
for (uint32_t i = 0; i < field_count; i += 1) {
TypeUnionField *union_field = &union_type->data.unionation.fields[i];
ZigType *field_type = resolve_union_field_type(g, union_field);
if (field_type == nullptr) {
union_type->data.unionation.resolve_status = ResolveStatusInvalid;
return ErrorSemanticAnalyzeFail;
}
}
union_type->data.unionation.resolve_loop_flag_other = false;
union_type->data.unionation.resolve_status = ResolveStatusSizeKnown;
return ErrorNone;
}
union_type->data.unionation.resolve_status = ResolveStatusZeroBitsKnown;
return ErrorNone;
}