diff --git a/src/Sema.zig b/src/Sema.zig index d526352778100012be4c44309b1f5c06f03b8475..1ff650b17b5918d4d732bf33209aee5741d4017d 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -17597,6 +17597,7 @@ fn zirIsNonNullPtr( const nullable_ty = ptr_ty.childType(zcu); try sema.checkNullableType(block, src, nullable_ty); + try sema.ensureLayoutResolved(nullable_ty, src, .ptr_access); if (try sema.resolveIsNullFromType(block, src, nullable_ty)) |is_null| { return .fromValue(.makeBool(!is_null)); @@ -31249,6 +31250,11 @@ fn resolveIsNonErrVal( return null; } +/// If `null` is the only possible value of type `ty`, returns `true`. +/// If `null` is *not* a possible value of `ty`, returns `false`. +/// Otherwise, if a value of type `ty` may or may not be `null`, returns `null`. +/// +/// Asserts that the layout of `ty` is resolved. fn resolveIsNullFromType( sema: *Sema, block: *Block, @@ -31256,6 +31262,8 @@ fn resolveIsNullFromType( ty: Type, ) CompileError!?bool { const zcu = sema.pt.zcu; + ty.assertHasLayout(zcu); + return switch (ty.zigTypeTag(zcu)) { else => false, .null => true,