Sema: handle foo() catch |err| switch (err) {...}
for !noreturn
#25203
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #25037. The issue there is that when analyzing a
switch_block_err_union
, we analyze the non-error case which includes anerr_union_payload_unsafe
instruction.zirErrUnionPayload
sees that the OPV of the payload isunreachable
, so it returns that without emitting any AIR. The assertion at the bottom ofanalyzeBodyInner
then fails becauseblock.instructions.items.len == 0
: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
onis_non_err
) when the payload type isnoreturn
.Just skipping the assertions above when
air_inst == .unreachable_value
also seemed to work fine, but didn't feel great. Same for adding asema.analyzeUnreachable(...)
inzirErrUnionPayload
.I also replaced
std.ArrayListUnmanaged
withstd.ArrayList
throughout Sema.