From 21c488ce68480d5298fc51f80f2c854d4ec8c364 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Wed, 25 Nov 2020 22:13:40 +0100 Subject: [PATCH] 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. --- src/stage1/analyze.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/stage1/analyze.cpp b/src/stage1/analyze.cpp index f9820158ed..c5a4a7aa2c 100644 --- a/src/stage1/analyze.cpp +++ b/src/stage1/analyze.cpp @@ -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; }