Skip to content

wasm: a named fn passed as a value fails to compile (UnboundVariable) — interp/Bun accept it #839

Backlog

Description

@hyperpolymath

Found by the #829 thread. Reproduced on main ee211d3.

fn nine(s: String) -> Int { 9 }
fn call(f: fn(String) -> Int) -> Int { f("x") }
fn main() -> () { println(int_to_string(call(nine))); }
  • interp and Bun-ESM: print 9.
  • core wasm: Code generation error: UnboundVariable "nine".

Classification: a loud divergence. It is refused at compile time, so nothing runs with a wrong value.

Options

Ranked by elegance and correctness first, then by dependability.

  1. (Recommended: most elegant and correct) Treat a named top-level function in value position as a closure. Its environment pointer is null (0), and it dispatches through a table entry pointing to a small trampoline that drops the environment argument. This reuses the existing closure ABI (func_id, env_ptr), so callers need no change. The same pass covers the intrinsic-as-value case (Bun-ESM: an intrinsic used as a value (e.g. len) emits a bare name — ReferenceError at run time #837) once intrinsics are eta-expanded.
  2. (Most dependable) Keep refusing, but name the cause: "a named fn cannot be passed as a value on core wasm yet; wrap it: |s| nine(s)".

Generated by Claude Code

Activity

  1. whatproblem-ai commented on Dec 1, 2026

    @whatproblem-ai

    Problem: On core wasm, passing a named top-level fn as a value (call(nine) where call takes fn(String) -> Int) fails at codegen with UnboundVariable "nine" on main ee211d3. The interpreter and Bun-ESM print 9. The failure happens at compile time, so no wrong value is produced.

    Expected: core wasm compiles and prints 9, matching interp and Bun. If that is not yet supported, the compiler should give an error that names the cause and suggests the |s| nine(s) workaround.


    Clarity: 93%. Clear enough to work on.

    ⌨️ Commands · 💬 Have feedback? Tell us · 🎯 New here? Add WhatProblem to your repo · 🔒 Privacy

  2. added
    bindings
    bug
    migration
    on Dec 1, 2026
  3. added
    architecture
    priority:p2
    scope:repo
    on Dec 1, 2026
  4. added 5 commits that reference this issue on Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    architecturebindingsbugmigrationpriority:p2scope:repo

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions