Skip to content

closures capture outer-scope let by value; mutations invisible after closure runs #588

@cs01

Description

@cs01

Bug

Closures capture outer-scope variables by value, not by reference. Mutations to a captured let inside a closure are not visible in the outer scope after the closure runs.

Example:

let done = false;
socket.on("connect", () => {
  done = true;          // modifies inner copy
});
// ...
if (!done) { /* this branch always runs even after 'connect' fires */ }

Impact

Event-driven code can't signal completion to the outer scope via captured flags. Hit in tests/fixtures/net/tcp-echo.ts (PR #585) — the test had to signal via stdout sentinel lines instead of a captured boolean.

Note

This is a design question as much as a bug — full reference capture requires box-allocation of captured vars. May need an RFC before implementation. Lower priority than the straight codegen bugs but should be tracked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstatus:plannedTracked, not scheduled

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions