zig
zig copied to clipboard
Bit-packed struct with undefined default has inconsistent access
Zig Version
0.13.0-dev.211+6a65561e3
Steps to Reproduce and Observed Behavior
Run the following code:
const std = @import("std");
pub const Foo = packed struct(u2) {
a: bool = undefined,
b: bool,
};
const foo = Foo{
.b = true,
};
pub fn main() void {
std.debug.print("{}\n", .{foo});
std.debug.print("{}\n", .{foo.b});
}
which prints
example.Foo{ .a = false, .b = false }
true
Notice how when we print foo
, we get .b = false
, but when we print foo.b
we get true
.
Expected Behavior
Both of them should print b
as being true
, but the first one doesn't.
A few things I've noticed:
- If you change the
undefined
default value withfalse
, then everything works as expected - Pretty recent regression, works in zig 0.12.0