zig icon indicating copy to clipboard operation
zig copied to clipboard

@unionInit should get its type from its result location

Open nektro opened this issue 1 year ago • 1 comments

Zig Version

0.12.0-dev.3381+7057bffc1

Steps to Reproduce and Observed Behavior

@unionInit(comptime Union: type, comptime active_field_name: []const u8, init_expr) Union

Expected Behavior

@unionInit(comptime active_field_name: []const u8, init_expr) Union
const U = union(enum) {
    a: u32,
    b: u16,
    c: u64,
};

test {
    const x: U = @unionInit("a", 0);
    _ = x;
}

natural continuation of https://github.com/ziglang/zig/issues/5909

nektro avatar Mar 21 '24 04:03 nektro

also meshes well with WIP changes to make @fieldParentPtr do the same

xdBronch avatar Mar 21 '24 04:03 xdBronch