Skip to content

Type conditionals that only partly diverge by their falling-through b… - #1788

Open
cburgdorf wants to merge 1 commit into
masterfrom
fix/continue-in-else-if-chain
Open

cburgdorf wants to merge 1 commit into
masterfrom
fix/continue-in-else-if-chain

Conversation

@cburgdorf

Copy link
Copy Markdown
Collaborator

…ranch

check_if typed an if/else by its else branch. When that branch diverged (return, continue, break) the whole conditional became !, even if the then branch fell through, e.g. the inner if of if a { return 1 } else if b { r = 3 } else { return 2 }. Lowering then treated the join after the chain as unreachable and replaced the following statements with an unreachable-code trap, so a loop like

while i < 4 {
    if i != 1 { i += 1; continue } else if i == 1 { } else { return 100 }
    i += 2
}

reverted on the EVM and trapped natively. check_match had the same problem for a last arm that diverges.

The divergence of a branch was also lost earlier: equate_ty answered a diverging expression with the expected type even while that was still an open type variable. It now keeps ! in that case, check_if uses the type of a branch that doesn't diverge, and check_match only becomes ! when every arm diverges.

…ranch

`check_if` typed an `if`/`else` by its `else` branch. When that branch
diverged (`return`, `continue`, `break`) the whole conditional became `!`,
even if the `then` branch fell through, e.g. the inner `if` of
`if a { return 1 } else if b { r = 3 } else { return 2 }`. Lowering then
treated the join after the chain as unreachable and replaced the following
statements with an unreachable-code trap, so a loop like

    while i < 4 {
        if i != 1 { i += 1; continue } else if i == 1 { } else { return 100 }
        i += 2
    }

reverted on the EVM and trapped natively. `check_match` had the same
problem for a last arm that diverges.

The divergence of a branch was also lost earlier: `equate_ty` answered a
diverging expression with the expected type even while that was still an
open type variable. It now keeps `!` in that case, `check_if` uses the type
of a branch that doesn't diverge, and `check_match` only becomes `!` when
every arm diverges.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-06T09:26:07.628742Z 52872b7 PR opened
🔒 Security Review ✅ Completed 2026-10-06T09:27:30.336665Z 52872b7 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

This branch has not been deployed

No deployments
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.

1 participant