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
self is undefined under --platform bun, and the member-object collapse hides it for builtin names #10306
Under --platform bun, self is not defined at all. bun defines it as a globalThis self-reference on the main thread, as browsers and Web Workers do.
Repro
// @ts-nocheckconsole.log("typeof self ",typeofself)// bun "object" perry "undefined"console.log("self === gT ",self===globalThis)// bun true perry falseself.x=1// bun ok perry TypeError:// Cannot set properties of null or undefined (setting 'x')console.log("self.Math.max ",self.Math.max(1,4))// bun 4 perry 4 ← still works
perry compile main.ts --platform bun.
Two things worth separating
self is missing.is_builtin_global_value_name lists it (with the comment "Web Worker scope aliases … installed on the worker thread's global object before its compiled entry runs"), but nothing installs it on the main thread. bun installs it on both. Node deliberately does not define self on the main thread, so if the node platform is meant to match Node this is a bun-platform-only gap — worth confirming which behaviour each platform should have rather than installing it unconditionally.
self.Math.max(1, 4) returns 4 anyway. The member-object collapse in lower/expr_member/member_tail.rs rewrites self.<builtin> to the intrinsic GlobalGet(0).<builtin> surface, so it never dereferences the (undefined) receiver. The result is that self.<builtin> silently works while self.<anything else> throws — the receiver is only consulted for the names that are not built in. Same mechanism as Reads through Node's global alias miss every user-installed property (global.x = v; global.x → undefined) #10303, where global.<x> collapsed and answered undefined for user-installed properties; the self case just has no receiver at all behind the collapse.
Found while checking whether self shared #10303's shape — it does, and it has an extra problem underneath.
Impact
Not currently blocking OpenCode (#10107); it does not use self. Filed because the collapse masking a missing global is the kind of thing that surfaces later as a confusing partial-success.
Activity