Repository navigation
hir: a static field initializer that constructs its own class gets the class's capture args in both copies - #15786
proggeramlug wants to merge 3 commits into
Conversation
…he class too A static field initializer is lowered before its class registers its captures, so `static mk = () => new Y(1)` in a class that captures `F` gets no forwarded capture args. The end-of-body pass appends them to the `new Y` sites of the lowered body only, on the premise that member code lives in the pending class. A static field initializer is body code that stands twice: in the body, where the class evaluation runs it, and in the class's static_fields, which emitted_closures takes as the arrow's one definition. The body copy captured [Y, F], the definition [Y], and the facts walk stopped on "shared emitted closure capture layout changed" (a CJS module or factory class with a static arrow constructing itself, Next.js RenderResult once its unread static private is a static block). Both end-of-body passes (arrow/function-declaration bodies and function expressions, the CJS wrapper) now append to the pending class's static field initializers as well, with the same outer ids: static field initializers keep the outer ids, synthesize_class_captures remaps only member bodies and instance fields.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
A class whose static field initializer constructs the class itself (
static mk = () => new Y(1)) crashed the compiler with "shared emitted closure capture layout changed" when the class is declared inside a function body (for example a CommonJS module wrapper).The static field initializer is lowered before the class registers its captures, so the
new Y(...)inside it gets its forwarded capture arguments from the end-of-body pass. That pass only rewrote the function body, but the initializer also lives in the class'sstatic_fields, which is the arrow's one emitted definition. The two copies ended up with different capture lists.append_new_args_in_declaring_body(class_captures.rs) now does the append on the body and on the pending class's static field initializers; both end-of-body passes (block bodies and function expressions) call it.Minimal repro (CJS module required from main):
Checks (qb10):
static_field_self_new(arrow and function-expression factory): passes with the fix, fails with it reverted.browser.ts:66:40) is lost identically on plain main 4a2ab6f against the gates' older main reference, so it is base drift, not this change. STOP c08/c09 and semver rc=0.Summary by CodeRabbit