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(...@@ -17597,6 +17597,7 @@ fn zirIsNonNullPtr(
17597 const nullable_ty = ptr_ty.childType(zcu);17597 const nullable_ty = ptr_ty.childType(zcu);
1759817598
17599 try sema.checkNullableType(block, src, nullable_ty);17599 try sema.checkNullableType(block, src, nullable_ty);
17600 try sema.ensureLayoutResolved(nullable_ty, src, .ptr_access);
1760017601
17601 if (try sema.resolveIsNullFromType(block, src, nullable_ty)) |is_null| {17602 if (try sema.resolveIsNullFromType(block, src, nullable_ty)) |is_null| {
17602 return .fromValue(.makeBool(!is_null));17603 return .fromValue(.makeBool(!is_null));
...@@ -31249,6 +31250,11 @@ fn resolveIsNonErrVal(...@@ -31249,6 +31250,11 @@ fn resolveIsNonErrVal(
31249 return null;31250 return null;
31250}31251}
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.
31252fn resolveIsNullFromType(31258fn resolveIsNullFromType(
31253 sema: *Sema,31259 sema: *Sema,
31254 block: *Block,31260 block: *Block,
...@@ -31256,6 +31262,8 @@ fn resolveIsNullFromType(...@@ -31256,6 +31262,8 @@ fn resolveIsNullFromType(
31256 ty: Type,31262 ty: Type,
31257) CompileError!?bool {31263) CompileError!?bool {
31258 const zcu = sema.pt.zcu;31264 const zcu = sema.pt.zcu;
31265 ty.assertHasLayout(zcu);
31266
31259 return switch (ty.zigTypeTag(zcu)) {31267 return switch (ty.zigTypeTag(zcu)) {
31260 else => false,31268 else => false,
31261 .null => true,31269 .null => true,