mirror of
https://github.com/ziglang/zig.git
synced 2025-12-16 19:23:08 +00:00
stage1: Create a new declaration scope for union enum types
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 #7532
This commit is contained in:
parent
83646df2cc
commit
e18abab55a
@ -3281,7 +3281,8 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
|
|||||||
tag_type->data.enumeration.src_field_count = field_count;
|
tag_type->data.enumeration.src_field_count = field_count;
|
||||||
tag_type->data.enumeration.fields = heap::c_allocator.allocate<TypeEnumField>(field_count);
|
tag_type->data.enumeration.fields = heap::c_allocator.allocate<TypeEnumField>(field_count);
|
||||||
tag_type->data.enumeration.fields_by_name.init(field_count);
|
tag_type->data.enumeration.fields_by_name.init(field_count);
|
||||||
tag_type->data.enumeration.decls_scope = union_type->data.unionation.decls_scope;
|
tag_type->data.enumeration.decls_scope = create_decls_scope(
|
||||||
|
g, nullptr, nullptr, tag_type, get_scope_import(scope), &tag_type->name);
|
||||||
} else if (enum_type_node != nullptr) {
|
} else if (enum_type_node != nullptr) {
|
||||||
tag_type = analyze_type_expr(g, scope, enum_type_node);
|
tag_type = analyze_type_expr(g, scope, enum_type_node);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -761,3 +761,18 @@ test "@unionInit on union w/ tag but no fields" {
|
|||||||
S.doTheTest();
|
S.doTheTest();
|
||||||
comptime S.doTheTest();
|
comptime S.doTheTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "union enum type gets a separate scope" {
|
||||||
|
const S = struct {
|
||||||
|
const U = union(enum) {
|
||||||
|
a: u8,
|
||||||
|
const foo = 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
fn doTheTest() void {
|
||||||
|
expect(!@hasDecl(@TagType(U), "foo"));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
S.doTheTest();
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user