Skip to content

fix(codegen-bun): rename shadowing let binders; type lambda Int callables - #827

Merged
hyperpolymath merged 6 commits into
mainfrom
claude/gifted-lamport-k0mc5l-bun-scope
Dec 1, 2026
Merged

hyperpolymath merged 6 commits into
mainfrom
claude/gifted-lamport-k0mc5l-bun-scope

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Two Bun-ESM miscompiles on main, found while answering review on #798. They are separate from the type-checker hole in #826.

1. A let that reads or shadows an enclosing name

A JS const x is in its temporal dead zone (TDZ) for its whole block, so the old emission failed in two ways:

Source Emitted on main Result
let y = { let x = x + 1; x }; const x = (x + 1) in the block ReferenceError
pub fn p(x: Int) -> Int { let x = x + 1; x } function p(x) { const x = (x + 1); … } SyntaxError: the whole module fails to load

Fix. A let binder is emitted under a fresh name$N when its initializer mentions the name, or when it shadows a name already bound in the function. $ cannot occur in a source identifier, so fresh names never collide.

References resolve through a scoped rename table in resolve_var. Binders that keep their own name clear the rename for their scope: parameters, lambda parameters, match arms and loops. Destructuring and punned record patterns are renamed the same way.

2. An Int-typed lambda parameter

pub fn lambda_int(s: String) -> Int {
  let f = fn(len: String -> Int) => len(s) / 2;
  f(fn(t: String) => 5)
}

This returned 2.5 on main: a function declared -> Int returned a non-integer. CodeRabbit left this open on #798. Lambda parameters are now seeded the way function parameters are. An untyped or non-Int parameter also stops a same-named outer Int from truncating.

Evidence

  • tests/codegen-bun/let_rebind has 7 cases. On main its module fails to load ("x" was originally declared here).
  • dune build @test/runtest: 662 tests pass. Bun-ESM: 9 harnesses. Legacy codegen-deno corpus: 42. Wasm: 48. All pass.
  • tools/check-soundness-ledger.sh passes. A ledger row follows in the next commit.

Generated by Claude Code

…bles

Two Bun-ESM miscompiles on main, both found while answering review on
#798.

A `let` that reads or shadows a name bound in an enclosing scope. JS
`const x` is in its temporal dead zone for its whole block, so

    let y = { let x = x + 1; x };

emitted `const x = (x + 1)` and threw ReferenceError, and

    pub fn p(x: Int) -> Int { let x = x + 1; x }

emitted `function p(x) { const x = ... }`, a SyntaxError that stops the
whole module loading. A `let` binder is now emitted under a fresh
`name$N` when its initializer mentions the name or it shadows a name
already bound in the function; references resolve through a scoped
rename table (resolve_var), which binders that keep their own name
(parameters, match arms, loops) clear for their scope. Destructuring
and punned record patterns are renamed the same way.

A lambda parameter typed `fn(..) -> Int` was not classified as an Int
callable, so `fn(len: String -> Int) => len(s) / 2` divided as a float
and a function declared `-> Int` returned 2.5. Lambda parameters are now
seeded like function parameters, and an untyped or non-Int one stops a
same-named outer Int from truncating.

tests/codegen-bun/let_rebind covers each case; on main the module fails
to load ("x" was originally declared here).

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

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 55 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 01ee69f0-7ef0-4e68-b163-850c87efcb94
Commits

Reviewing files that changed from the base of the PR and between 0cf73b2 and 9fddbc9.

Files selected for processing: 8

  • .gitignore
  • docs/SOUNDNESS.adoc
  • lib/codegen_deno.ml
  • test/test_let_rebind_bun.ml
  • test/test_main.ml
  • tests/codegen-bun/let_rebind.affine
  • tests/codegen-bun/let_rebind.harness.mjs
  • tools/soundness-anchors.sha256
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@gitnotebooks

gitnotebooks Bot commented Nov 30, 2026

Copy link
Copy Markdown

…dger

test/test_let_rebind_bun.ml checks the emitted JS for each case (five of
its six fail on main; the sixth is the unshadowed control). It is the
ledger anchor, since the gate digests test/*.ml suites; the Bun harness
in tests/codegen-bun/let_rebind keeps checking run-time behaviour.

Adds the #827 row to docs/SOUNDNESS.adoc and reseals
tools/soundness-anchors.sha256.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J4QvDiosfvobXq67wbduuK
…h writes

tools/run_codegen_bun_tests.sh check 5 writes tests/codegen-bun/deno-removed.json
on every run; its .log sibling and backend-conflict.json are already ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J4QvDiosfvobXq67wbduuK
@hyperpolymath
hyperpolymath marked this pull request as ready for review December 1, 2026 17:30
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-12-01T17:30:34.432640Z
We couldn’t complete this review. Comment @codex review to try again.
8bb8456 Draft marked ready
ℹ️ 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@sonarqubecloud

sonarqubecloud Bot commented Dec 1, 2026

Copy link
Copy Markdown

@hyperpolymath
hyperpolymath enabled auto-merge (squash) December 1, 2026 18:35
@hyperpolymath
hyperpolymath merged commit 84eca60 into main Dec 1, 2026
18 checks passed
@hyperpolymath
hyperpolymath deleted the claude/gifted-lamport-k0mc5l-bun-scope branch December 1, 2026 18:41
hyperpolymath pushed a commit that referenced this pull request Dec 1, 2026
Conflict in test/test_main.ml: both sides added a suite to the list
(#832 here, #827 on main). Both kept.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J4QvDhJog6g9kprphCAadr
hyperpolymath pushed a commit that referenced this pull request Dec 1, 2026
The owner's merge of main (46b1a64) brought in #827, which changes
lib/codegen_deno.ml, a soundness path. Re-verified this branch merged
with main at 84eca60: dune runtest --force 817 + 32 + 3 tests pass, and
the #555/#623 xfail pin is live; codegen corpora 48 wasm + 42 legacy
Bun-ESM + 9 native Bun harnesses pass; all 5 guards OK.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J4QvDfgDTxx9Bumfa2XXcQ
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.

2 participants