| author | |
| committer | |
| log | e18abab55aea4a5c3b347274e41de9fdc24e950c |
| tree | fdf2716108151ffcddde84eaf5431fb27fbfac5f |
| parent | 83646df2cce59f254822355ec1ceeb6884e1177e |
Making the enum type share the scope with the parent union means every
declaration "bleeds" into the enum scope.
Let's mint a fresh empty scope for the enum type.
Thanks to @Vexu for the test case.
Closes #75322 files changed, 17 insertions(+), 1 deletions(-)
src/stage1/analyze.cpp+2-1| ... | ... | @@ -3281,7 +3281,8 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 3281 | 3281 | tag_type->data.enumeration.src_field_count = field_count; |
| 3282 | 3282 | tag_type->data.enumeration.fields = heap::c_allocator.allocate<TypeEnumField>(field_count); |
| 3283 | 3283 | tag_type->data.enumeration.fields_by_name.init(field_count); |
| 3284 | tag_type->data.enumeration.decls_scope = union_type->data.unionation.decls_scope; | |
| 3284 | tag_type->data.enumeration.decls_scope = create_decls_scope( | |
| 3285 | g, nullptr, nullptr, tag_type, get_scope_import(scope), &tag_type->name); | |
| 3285 | 3286 | } else if (enum_type_node != nullptr) { |
| 3286 | 3287 | tag_type = analyze_type_expr(g, scope, enum_type_node); |
| 3287 | 3288 | } else { |
test/stage1/behavior/union.zig+15| ... | ... | @@ -761,3 +761,18 @@ test "@unionInit on union w/ tag but no fields" { |
| 761 | 761 | S.doTheTest(); |
| 762 | 762 | comptime S.doTheTest(); |
| 763 | 763 | } |
| 764 | ||
| 765 | test "union enum type gets a separate scope" { | |
| 766 | const S = struct { | |
| 767 | const U = union(enum) { | |
| 768 | a: u8, | |
| 769 | const foo = 1; | |
| 770 | }; | |
| 771 | ||
| 772 | fn doTheTest() void { | |
| 773 | expect(!@hasDecl(@TagType(U), "foo")); | |
| 774 | } | |
| 775 | }; | |
| 776 | ||
| 777 | S.doTheTest(); | |
| 778 | } |