Skip to content

[codegen] concreteClass propagation through closure capture breaks stage1 binary-type check #646

@cs01

Description

@cs01

Context

Attempted fix for #640 Step 3b (setInterval capture segfault) in PR #644 — closed.

Real root cause (not as #640 describes): captured class instance in a closure loses its concrete class name → capturedVar.field can't find GEP → final load uses field's nominal type against whatever alloca holds. Pointer-typed fields segfault; number fields silently return garbage.

Minimal repro:

class T { h: string = "hello"; }
const t = new T();
setTimeout(() => { console.log(t.h); }, 10);

Prints garbage on main.

Attempted fix (failed)

Plumb concreteClass through ClosureAnalyzer + generateArrowFunction, re-bind captured locals with createClassMetadata instead of plain defineVariable (~60 LOC diff across 8 files).

Failed on stage1/2 regression: fixture semantic/binary-type-in-function (rejects "hello" - 5 with "cannot use '-' between 'string' and 'number'") started passing silently — no compile error emitted. Stage1 compiler built from modified source lost the binary-type-mismatch check somewhere in the re-bind path.

Next

Needs someone to diagnose why the re-bind logic in variable-allocator.ts/closure-analyzer.ts interacts with semantic binary-type checking. Likely the re-bind overwrites type metadata the type-inference pass depended on.

Branch step3b-setinterval-segfault closed; diff available via PR #644 history.

Blocks: #640 Step 3b completion.

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