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:
glowsquid
2026-04-10 23:31:21 +02:00
committed by mlugg
parent 2c6e5006ed
commit 8111d3d63c
2 changed files with 19 additions and 1 deletions
+8
View File
@@ -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;
}