authorgravatar for pentuppup@noreply.codeberg.orgpentuppup <pentuppup@noreply.codeberg.org> 2026-10-01 13:05:37-04:00
committergravatar for pentuppup@noreply.codeberg.orgpentuppup <pentuppup@noreply.codeberg.org> 2026-10-01 17:45:52-04:00
log96bae851666ada20b77294212a5dcca4dbc50533
tree0f9bb1fd163cc1081d6a1537e55083b0d6ad5661
parent7f8f2b16a0a523a1473b172e9f8a585087e879fc

InternPool: inherit captures from owner union in generated enums


2 files changed, 18 insertions(+), 1 deletions(-)

src/InternPool.zig+1-1
......@@ -3851,7 +3851,7 @@ pub fn loadEnumType(ip: *const InternPool, index: Index) LoadedEnumType {
38513851 .generated_union_tag => info: {
38523852 const owner_union: Index = @fromBackingInt(@intCast(extra_items[extra_index]));
38533853 extra_index += 1;
3854 break :info .{ .none, .empty, owner_union };
3854 break :info .{ .none, ip.loadUnionType(owner_union).captures, owner_union };
38553855 },
38563856 _ => |n| info: {
38573857 const zir_index: TrackedInst.Index = @fromBackingInt(@intCast(extra_items[extra_index]));
test/behavior/union.zig+17
......@@ -2178,6 +2178,23 @@ test "matching captures causes union equivalence" {
21782178 try expect(a.u == b.u);
21792179}
21802180
2181test "capture used as explicit field value" {
2182 const S = struct {
2183 fn Union(n: u8) type {
2184 return union(enum(u8)) {
2185 a: u32 = n,
2186 b,
2187 };
2188 }
2189 };
2190
2191 comptime assert(@typeInfo(S.Union(0)).@"union".tag_type.? != @typeInfo(S.Union(1)).@"union".tag_type.?);
2192
2193 const s: S.Union(1) = .{ .a = 0 };
2194 try expect(@backingInt(s) == 1);
2195 try expect(@backingInt(@as(@typeInfo(S.Union(1)).@"union".tag_type.?, s)) == 1);
2196}
2197
21812198test "signed enum tag with negative value" {
21822199 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
21832200 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;