diff options
| author | LemonBoy <thatlemon@gmail.com> | 2020-11-25 22:13:40 +0100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-11-26 10:49:47 -0800 |
| commit | 21c488ce68480d5298fc51f80f2c854d4ec8c364 (patch) | |
| tree | 25f476910193cd8a0c7de25ef2fdec392ca091f7 /src/stage1/analyze.cpp | |
| parent | 58365c4e79479157bb0b4c2d66ad96c9a394651d (diff) | |
| download | zig-21c488ce68480d5298fc51f80f2c854d4ec8c364.tar.gz zig-21c488ce68480d5298fc51f80f2c854d4ec8c364.zip | |
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.
Diffstat (limited to 'src/stage1/analyze.cpp')
| -rw-r--r-- | src/stage1/analyze.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
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; } |
