fix handling of comptime-only union fields in Type.getUnionLayout (#25182)

Fixes #25180
This commit is contained in:
Silver
2025-09-18 05:39:47 +01:00
committed by Alex Rønne Petersen
parent 87ca304a02
commit e14540399c
2 changed files with 29 additions and 9 deletions

View File

@@ -2321,3 +2321,21 @@ test "initialize empty field of union inside comptime-known struct constant" {
const val: Wrapper = .{ .inner = .{ .none = {} } };
comptime assert(val.inner.none == {});
}
test "union with function body field" {
const U = union {
f: fn () void,
fn foo() void {}
fn bar() void {}
};
const x: U = .{ .f = U.foo };
try std.testing.expect(x.f == U.foo);
x.f();
comptime var y: U = .{ .f = U.bar };
try std.testing.expect(y.f == U.bar);
y.f();
y.f = U.foo;
try std.testing.expect(y.f == U.foo);
y.f();
}