Skip to content

fix: for-of on class array filter/sort/slice results#402

Merged
cs01 merged 1 commit intomainfrom
fix/for-of-filter-class-array
Mar 14, 2026
Merged

fix: for-of on class array filter/sort/slice results#402
cs01 merged 1 commit intomainfrom
fix/for-of-filter-class-array

Conversation

@cs01
Copy link
Owner

@cs01 cs01 commented Mar 14, 2026

Summary

  • for (const t of arr.filter(...)) on class arrays produced garbage when accessing fields — the element type was lost through the filter/sort/slice/reverse methods
  • Root cause: three places needed to propagate the class element type through array-preserving methods:
    1. getObjectArrayElementType (type-inference.ts) — added variable and array literal cases, plus recursive resolution through filter/sort/reverse/slice
    2. getIterableClassElementType (control-flow.ts) — propagate element type through array-preserving method calls
    3. generateGlobalVariableDeclarations (llvm-generator.ts) — use getObjectArrayElementType when resolvedBase is "object" to find the actual class name

Test plan

  • New fixture arrays/class-array-for-of-filter.tsfor...of on filter result + sort result
  • Index access on filter result still works (done[0].name)
  • All existing tests pass
  • Self-hosting Stage 1 passes

🤖 Generated with Claude Code

@cs01 cs01 merged commit c3e1b43 into main Mar 14, 2026
12 checks passed
@cs01 cs01 deleted the fix/for-of-filter-class-array branch March 14, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant