Repository navigation
fix(codegen-bun): rename shadowing let binders; type lambda Int callables - #827
Conversation
…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
|
Warning Review limit reachedYou'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. View limit details
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. |
|
Review these changes at https://app.gitnotebooks.com/hyperpolymath/affinescript/pull/827 |
…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
…-k0mc5l-bun-scope
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
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
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



Two Bun-ESM miscompiles on
main, found while answering review on #798. They are separate from the type-checker hole in #826.1. A
letthat reads or shadows an enclosing nameA JS
const xis in its temporal dead zone (TDZ) for its whole block, so the old emission failed in two ways:mainlet y = { let x = x + 1; x };const x = (x + 1)in the blockReferenceErrorpub fn p(x: Int) -> Int { let x = x + 1; x }function p(x) { const x = (x + 1); … }SyntaxError: the whole module fails to loadFix. A
letbinder is emitted under a freshname$Nwhen 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
This returned
2.5onmain: a function declared-> Intreturned 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 outerIntfrom truncating.Evidence
tests/codegen-bun/let_rebindhas 7 cases. Onmainits 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.shpasses. A ledger row follows in the next commit.Generated by Claude Code