mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
fix comptime @ptrcasting from a larger type to a smaller one (#31774)
closes #30180 Note from mlugg: this fix is very much a hack, but it definitely won't break anything and it demonstrably fixes one case, so I'm merging it for now with the expectation that I'll be replacing the broken code soon. Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31774 Reviewed-by: mlugg <mlugg@noreply.codeberg.org> Co-authored-by: glowsquid <sachabarsayuracko@gmail.com> Co-committed-by: glowsquid <sachabarsayuracko@gmail.com>
This commit is contained in:
@@ -562,3 +562,11 @@ test "@ptrCast array pointer removing sentinel" {
|
||||
comptime assert(out[2] == 3);
|
||||
comptime assert(out[3] == 4);
|
||||
}
|
||||
|
||||
test "@ptrcast larger type to smaller one" {
|
||||
const T = packed struct { x: u17 };
|
||||
const a: u32 = 0;
|
||||
const b: *const T = @ptrCast(&a);
|
||||
const c = b.x;
|
||||
_ = c;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user