Skip to content

fix(analyser): give a while true loop no break leaves no value 🔁 - #337

Merged
timfennis merged 1 commit into
feat/type-checkerfrom
fix/endless-while-never
Nov 13, 2026
Merged

timfennis merged 1 commit into
feat/type-checkerfrom
fix/endless-while-never

Conversation

@timfennis

Copy link
Copy Markdown
Owner

A while loop always had the unit type, even while true with no break, which only ends by returning. A function whose body ends in one therefore returned the join of its returns and (), which is Any, and everything computed from its result was Any too. Found in an Advent of Code solution: fn merge_ranges(ranges) { … while true { … if done { return rc; } … } } made rr Any, so [(hi - lo + 1) for (lo, hi) in rr].sum failed to find a sum for List<Any>.

A while true loop that no break leaves now has type Never, like a return or Rust's loop without a break, so a function ending in one returns what its returns do. A break inside a nested loop leaves that loop, not this one. To tell, the analyser's loop depth became a stack of loops that records whether a break leaves each.

The manual's while-loop page describes it.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T16:58:52.224029Z 06b8c42 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.

@timfennis
timfennis merged commit 475535b into feat/type-checker Nov 13, 2026
1 check passed
@timfennis
timfennis deleted the fix/endless-while-never branch November 13, 2026 16:59
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