authorgravatar for sstochi@noreply.codeberg.orgsstochi <sstochi@noreply.codeberg.org> 2026-08-28 09:15:17+02:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-08-28 09:15:17+02:00
loga4f0c4a91dd9c9ab67f2884e6461e6168267335e
treec486375b74bd1204c61cbcf36b5bbb537bd27ea8
parente19a73c2d5b61d783470daa8aabbaba23ceb4578

Sema: resolve type layout in `zirIsNonNullPtr`

Resolves: https://codeberg.org/ziglang/zig/issues/36628 Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36643 Reviewed-by: mlugg <mlugg@mlugg.co.uk>

1 files changed, 8 insertions(+), 0 deletions(-)

src/Sema.zig+8
......@@ -17597,6 +17597,7 @@ fn zirIsNonNullPtr(
1759717597 const nullable_ty = ptr_ty.childType(zcu);
1759817598
1759917599 try sema.checkNullableType(block, src, nullable_ty);
17600 try sema.ensureLayoutResolved(nullable_ty, src, .ptr_access);
1760017601
1760117602 if (try sema.resolveIsNullFromType(block, src, nullable_ty)) |is_null| {
1760217603 return .fromValue(.makeBool(!is_null));
......@@ -31249,6 +31250,11 @@ fn resolveIsNonErrVal(
3124931250 return null;
3125031251}
3125131252
31253/// If `null` is the only possible value of type `ty`, returns `true`.
31254/// If `null` is *not* a possible value of `ty`, returns `false`.
31255/// Otherwise, if a value of type `ty` may or may not be `null`, returns `null`.
31256///
31257/// Asserts that the layout of `ty` is resolved.
3125231258fn resolveIsNullFromType(
3125331259 sema: *Sema,
3125431260 block: *Block,
......@@ -31256,6 +31262,8 @@ fn resolveIsNullFromType(
3125631262 ty: Type,
3125731263) CompileError!?bool {
3125831264 const zcu = sema.pt.zcu;
31265 ty.assertHasLayout(zcu);
31266
3125931267 return switch (ty.zigTypeTag(zcu)) {
3126031268 else => false,
3126131269 .null => true,