Skip to content

Commit

Permalink
stage1: Force union member types to be resolved
Browse files Browse the repository at this point in the history
No test case because I couldn't reduce the huuuge test case.
Fixes the problem discovered by @ifreund.
  • Loading branch information
LemonBoy authored and andrewrk committed Nov 26, 2020
1 parent 41d57b0 commit 36b8f5d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/stage1/analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3484,7 +3484,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;
}
Expand Down

0 comments on commit 36b8f5d

Please sign in to comment.