Skip to content

Bun-ESM: an intrinsic used as a value (e.g. len) emits a bare name — ReferenceError at run time #837

Backlog

Description

@hyperpolymath

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

Evidence

fn apply(f: fn(String) -> Int, s: String) -> Int { f(s) }
fn main() -> () { println(int_to_string(apply(len, "abc"))); }
Backend Result
interp 3
Bun-ESM ReferenceError: len is not defined, at run time
core wasm Codegen.UnboundVariable "len", at compile time: refused loudly, in the right phase

Classification

Loud divergence: the failure comes at run time when it should come at compile time. This is the same class as #832.

Options

Ranked by elegance and correctness first, then by dependability.

  1. (Recommended: most elegant and correct) Eta-expand an intrinsic used as a value at codegen: len becomes (s) => __lowered_len(s), so intrinsics become first-class on every backend. Doing it once in a shared pre-codegen pass (ExprVar intrinsic not in call position, giving ExprLambda) fixes Bun, JS and wasm together, because wasm already lowers closures.
  2. (Most dependable) Refuse an intrinsic in value position at codegen on Bun-ESM, as wasm already does. This is a loud compile-time error. It pairs with the closed-world check in js backend: string builtins are not lowered and crash at run time (ReferenceError) instead of being refused at compile time #832.

Generated by Claude Code

Activity

  1. whatproblem-ai commented on Dec 1, 2026

    @whatproblem-ai

    Problem: On Bun-ESM, an intrinsic used as a value (e.g. len passed to apply) is emitted as a bare name. The build succeeds, then fails at run time with ReferenceError: len is not defined. Interp prints 3, and core wasm refuses at compile time with Codegen.UnboundVariable "len". Reproduced on main ee211d3. Same class as #832.

    Expected: Either the intrinsic works as a first-class value on every backend (option 1), or Bun-ESM refuses it at compile time, as wasm does (option 2).

    Missing: choice between option 1 and option 2, confirmation that other intrinsics in value position hit the same failure


    Clarity: 93%. Clear enough to work on.

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

  2. coderabbitai commented on Dec 1, 2026

    @coderabbitai
    Contributor
    ⚠️ Possible Duplicate Issue(s)


    📝 Issue Planner

    Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.

    • Create Plan

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord!

  3. added
    architecture
    bindings
    bug
    priority:p2
    scope:repo
    status:ready
    on Dec 1, 2026
  4. added 4 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

    architecturebindingsbugpriority:p2scope:repostatus:ready

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions