You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
wasm: a local/parameter does not shadow a same-named top-level fn (silent wrong value); closure call types not interned (invalid wasm) #838
architectureStructural/system-level shape and runtime behaviourbindingsABI, FFI, WASM, and cross-language interop surfacesbugSomething is broken or behaves incorrectlypriority:p1High - schedule nextscope:repoConfined to this repositorystatus:readyFully specified and ready to be picked up
core wasm: prints 7. The call goes to the top-level helper and silently ignores the argument. This happens with any name, and also with a let-bound closure.
While fixing this, I found a second bug in the same area. A higher-order function compiled before any function with its closure signature produces invalid wasm (CompileError: WebAssembly.Module doesn't validate):
Silent wrong value. The generic ExprApp arm of gen_expr (lib/codegen.ml) checked func_indices before ctx.locals. The ExprVar and value paths already checked locals first.
Invalid wasm (loud). The three CallIndirect sites looked up the signature in the type section but never added it. If the signature was absent, they returned the next free index, and a later, different type then took that slot.
This complements #824, which stopped a parameter from pulling in a module import. That PR changed only the import filter. This issue is about call lowering.
Classification
(1) is a soundness hole: a silent wrong value.
(2) is a loud divergence: the module fails to load.
Fix
The fix is in a draft PR:
Look up locals first in the call arm and in expr_val_type.
Add one intern_type helper, used at all three CallIndirect sites.
Problem: In core wasm codegen, a call through a local or parameter (or let-bound closure) that shares a name with a top-level fn resolves to the top-level fn. The argument is silently ignored and the wrong value comes back (7 instead of 9). Separately, a higher-order fn compiled before any fn with its closure signature emits a CallIndirect type index that was never interned, so the module fails validation.
Expected: wasm matches interp and Bun-ESM (prints 9), and both repros produce valid modules.
architectureStructural/system-level shape and runtime behaviourbindingsABI, FFI, WASM, and cross-language interop surfacesbugSomething is broken or behaves incorrectlypriority:p1High - schedule nextscope:repoConfined to this repositorystatus:readyFully specified and ready to be picked up
Activity
whatproblem-ai commentedon Dec 1, 2026
Problem: In core wasm codegen, a call through a local or parameter (or let-bound closure) that shares a name with a top-level fn resolves to the top-level fn. The argument is silently ignored and the wrong value comes back (
7instead of9). Separately, a higher-order fn compiled before any fn with its closure signature emits aCallIndirecttype index that was never interned, so the module fails validation.Expected: wasm matches interp and Bun-ESM (prints
9), and both repros produce valid modules.Missing: link to the draft PR
Clarity: 94%. Clear enough to work on.
⌨️ Commands · 💬 Have feedback? Tell us · 🎯 New here? Add WhatProblem to your repo · 🔒 Privacy
docs(audit): add #838 (local does not shadow fn on wasm, fixed in #840)…
docs(audit): add #838 (local does not shadow fn on wasm, fixed in #840)…
docs(audit): #840 merged — mark #838 fixed
docs(soundness): restore the #826 ledger row lost in the main merge
docs(audit): add #838 (local does not shadow fn on wasm, fixed in #840)…
docs(audit): #840 merged — mark #838 fixed
fix(codegen): start the wasm heap after the last data segment (#830) (#…