mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 12:59:04 +00:00
Sema: fix memory management of union enum tag int tag
This likely went unnoticed due to all power of two integer types being special cased. Closes #13812
This commit is contained in:
parent
41913ddb1a
commit
e6588857df
@ -30757,16 +30757,17 @@ fn generateUnionTagTypeNumbered(
|
||||
new_decl.name_fully_qualified = true;
|
||||
errdefer mod.abortAnonDecl(new_decl_index);
|
||||
|
||||
const copied_int_ty = try int_ty.copy(new_decl_arena_allocator);
|
||||
enum_obj.* = .{
|
||||
.owner_decl = new_decl_index,
|
||||
.tag_ty = int_ty,
|
||||
.tag_ty = copied_int_ty,
|
||||
.fields = .{},
|
||||
.values = .{},
|
||||
};
|
||||
// Here we pre-allocate the maps using the decl arena.
|
||||
try enum_obj.fields.ensureTotalCapacity(new_decl_arena_allocator, fields_len);
|
||||
try enum_obj.values.ensureTotalCapacityContext(new_decl_arena_allocator, fields_len, .{
|
||||
.ty = int_ty,
|
||||
.ty = copied_int_ty,
|
||||
.mod = mod,
|
||||
});
|
||||
try new_decl.finalizeNewArena(&new_decl_arena);
|
||||
|
||||
@ -1465,3 +1465,12 @@ test "Namespace-like union" {
|
||||
var a: DepType.Version.Git = .tag;
|
||||
try expect(a.frozen());
|
||||
}
|
||||
|
||||
test "union int tag type is properly managed" {
|
||||
const Bar = union(enum(u2)) {
|
||||
x: bool,
|
||||
y: u8,
|
||||
z: u8,
|
||||
};
|
||||
try expect(@sizeOf(Bar) + 1 == 3);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user