Skip to content

Conversation

JackoCoolio
Copy link
Contributor

Fixes #25037. The issue there is that when analyzing a switch_block_err_union, we analyze the non-error case which includes an err_union_payload_unsafe instruction. zirErrUnionPayload sees that the OPV of the payload is unreachable, so it returns that without emitting any AIR. The assertion at the bottom of analyzeBodyInner then fails because block.instructions.items.len == 0:

if (sema.isNoReturn(air_inst)) {
    // We're going to assume that the body itself is noreturn, so let's ensure that now
    assert(block.instructions.items.len > 0);
    assert(sema.isNoReturn(block.instructions.items[block.instructions.items.len - 1].toRef()));
    break;
}

https://github.com/ziglang/zig/blob/0b75a2a1b1972777350c33c27cfe720172491de6/src/Sema.zig#L1979C9-L1984C10


My fix was just not analyzing the non-error case (by not bothering with the cond_br on is_non_err) when the payload type is noreturn.

Just skipping the assertions above when air_inst == .unreachable_value also seemed to work fine, but didn't feel great. Same for adding a sema.analyzeUnreachable(...) in zirErrUnionPayload.

I also replaced std.ArrayListUnmanaged with std.ArrayList throughout Sema.

@alexrp alexrp requested a review from mlugg September 10, 2025 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic when running sema on an error union switch.
1 participant