Sema: fix is_non_null_ptr handling for runtime-known pointers

We can still often determine a comptime result based on the type, even
if the pointer is runtime-known.

Also, we previously used load -> is non null instead of AIR
`is_non_null_ptr` if the pointer is comptime-known, but that's a bad
heuristic. Instead, we should check for the pointer to be
comptime-known, *and* for the load to be comptime-known, and only in
that case should we call `Sema.analyzeIsNonNull`.

Resolves: #22556
This commit is contained in:
mlugg
2025-01-20 13:34:47 +00:00
committed by Matthew Lugg
parent b9198b708f
commit 8bcb578507
4 changed files with 42 additions and 21 deletions

View File

@@ -498,6 +498,20 @@ test "optional of noreturn used with orelse" {
try expect(val == 123);
}
test "mutable optional of noreturn" {
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
var a: ?noreturn = null;
if (a) |*ptr| {
_ = ptr;
@compileError("bad");
} else {
// this is what we expect to hit
return;
}
@compileError("bad");
}
test "orelse on C pointer" {
// TODO https://github.com/ziglang/zig/issues/6597