Skip to content

fix(ts): diverging calls through closures and generics at ! pass tsc - #48

Merged
kixelated merged 3 commits into
mainfrom
quest/m2/ts-never-edges
Oct 25, 2026
Merged

kixelated merged 3 commits into
mainfrom
quest/m2/ts-never-edges

Conversation

@kixelated

@kixelated kixelated commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Two shapes #28 left fail tsc (quest):

  • A call to a closure that returns !. tsc treats a call as diverging only when the callee's binding has a declared type, and THIR bound the closure as an unannotated const. A tail fail(b) failed TS2366, and let x: u8 = if c { fail(b) } else { .. } failed TS2454. A fn(u8) -> ! pointer and a closure a function returns had the same problem.
  • A generic instantiated at ! (edition 2024's fallback, as in pass(panic!(..))). From THIR, its body read a never parameter and fell off the end (TS2534), and a panic! argument lowered to undefined (TS2345). From MIR, a generic of type ! that is reachable, such as unwrap_or_bail::<!>(None, b), returned return; (TS2322) and passed a ! local as undefined (TS2345).

Approach

  • THIR: a let of a closure or function pointer whose output is ! declares its type. MIR already declares every local's type.
  • THIR: a place of type ! reads through rt.unreachable(place), as match x {} already did. A tail-less block of type ! where a value goes, which is what panic!(..) expands to, goes through an unassigned temp, as NeverToAny has since fix(ts): type-check values of type ! where a value goes #28.
  • MIR: a Return from a function of type ! lowers as Unreachable does, and a read of a ! local is rt.unreachable(undefined) instead of undefined.

New cases in the lang fixture's diverging, under both lowerings. A random first byte rarely picks their trigger values, so caller.ts now exports cases that hit each one, with and without a second byte. All 14 panic in the translation with native's message. Each failure above reproduced on this branch before its fix.

Impact

  • No public API change. Output changes only for these shapes, which failed tsc before. The codec and task snapshots are unchanged, and just ts moq still passes.

Alternatives

  • throw f(b) after any call of type ! through something other than a function item. It covers every callee form without relying on tsc's declared-type rule, but it adds a statement to every such call site. MIR's typed locals already show the declaration is enough.
  • Not emitting a call once an argument diverges, as MIR does. That keeps pass::<!> out of the THIR output entirely, but THIR's expr has to return a value, and THIR is going away (quest).
  • return x instead of rt.unreachable(x) for a ! place. That reads better at a tail, but only works there.

Follow-ups

  • A closure bound by a destructuring pattern (let (f, g) = ..) is still an unannotated binding element in THIR, so tsc may not see a call to it diverge. No fixture hits this, and it goes away with THIR.

(written by Opus 5.5)

🤖 Generated with Claude Code

https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

kixelated and others added 2 commits October 24, 2026 22:43
Quest-Claim: 06ccf5d7cd664d3b
A binding of a closure or function pointer that never returns declares its
type, so `tsc` sees a call to it diverge. A value of type `!` is never
`undefined`: a place of type `!` reads through `rt.unreachable`, a
`panic!` block where a value goes leaves an unassigned temp, and from MIR,
a `Return` from a function of type `!` is unreachable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
@kixelated kixelated changed the title Diverging calls through closures and generics fix(ts): diverging calls through closures and generics at ! pass tsc Oct 25, 2026
@kixelated
kixelated marked this pull request as ready for review October 25, 2026 06:07
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 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-25T14:46:57.277488Z 3488a1d New commits
🔒 Security Review ✅ Completed 2026-10-25T14:48:41.812211Z 3488a1d New commits
ℹ️ 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.

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review by review (OpenAI)

Reviewed commit: 5cf4ba3

No actionable bugs found. Declaring diverging callee bindings and reusing existing unreachable/temporary lowering is a focused approach, avoiding additional throw statements at every call site. Deterministic fixture inputs meaningfully target the newly supported never-returning closure and generic paths in both lowerings. Destructured closure bindings remain the documented THIR follow-up, not a newly introduced finding.

Verification: static inspection of changed lowering paths, surrounding binding/place handling and added fixtures/snapshots. I did not execute TypeScript checks or native-versus-translated tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
@kixelated

Copy link
Copy Markdown
Collaborator Author

Merging. Since the review, the only change is a merge of origin/main (#41), which touches none of this PR's files. just check, just test, and quest check --base origin/main pass, CI is green on 3488a1d, and Codex reported no findings.

Decisions, as the maintainer accepted them:

  • A ! place reads as rt.unreachable(x), matching match x {} and MIR's Unreachable.
  • A binding of a closure or function pointer that never returns gets a type annotation, not a throw at each call site.
  • The new paths are reached through explicit cases in caller.ts. The random byte stream is unchanged.

(written by Opus 5.5)

@kixelated
kixelated merged commit 455e768 into main Oct 25, 2026
1 check passed
kixelated added a commit that referenced this pull request Oct 25, 2026
Regenerates the snapshots for the cases #48 and #49 added, and names `!`
and `()` in a suffix (`pass$never`), which printed as an empty part.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
@kixelated
kixelated deleted the quest/m2/ts-never-edges branch October 27, 2026 20:32
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