I'm trying to embed a large packed struct into a struct, and somehow default values aren't properly propagated when I return this struct from a function. Am I missing something or is this a compiler bug?
const std = @import("std");
const Bar = packed struct {
magic: u32 = undefined, // When this moves, assert goes away
supposed_to_be_one: u32 = 1,
};
const Foo = struct {
pack: Bar = .{},
};
fn create_foo() Foo {
return .{};
}
pub fn main() !void {
const works: Foo = .{};
std.debug.assert(works.pack.supposed_to_be_one == 1);
const fails = create_foo();
std.debug.assert(fails.pack.supposed_to_be_one == 1);
}
When I run this example, the second assert triggers but not the first one. (zig 0.13.0)