fix handling of comptime-only union fields in Type.getUnionLayout (#25182)
Fixes #25180
This commit is contained in:
committed by
Alex Rønne Petersen
parent
87ca304a02
commit
e14540399c
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user