Skip to content

-mm=own: for-of over a field of this in a generator reads the field at each step (TSLANG 182) - #1019

Merged
ASDAlexander77 merged 1 commit into
mainfrom
tslang-182
Nov 24, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
tslang-182

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

TSLANG 182, item 158 under your ruling of 2026-11-24 (own only). This PR is stacked on #1018; once #1018 merges, its base becomes main.

Fixed

  • -mm=own: for (const s of this.items) yield s in a generator method: "a value that borrows a field cannot be stored, returned or captured". The loop kept the field's array in the generator's state across its yields.
    • Under own, a for...of in a generator over an array field reached from this (this.items, this.inner.words) now reads the field again at each step: for (let .i = 0; .i < this.items.length; .i++) { const s = this.items[.i]; ... }.
    • break, continue, a destructuring element and a loop variable declared before the loop work as before.
    • A field assigned during the loop is followed, which JavaScript's for-of would not do. Your ruling accepts this.
    • The other memory models are unchanged.

Still open

  • Under own, a field whose elements are objects (for (const o of this.objs) yield o.n) is still refused, as it already is when the loop is written with an index. A generator's local lives in its state, and it can't hold a borrow of an element.

Verified

  • Full ctest: only the 10 failures that also fail locally on main.
  • 00own_generator_for_of_this_field.ts passes under gc, rc, own and none.
  • A loop over a field reassigned in the body prints a1 under own and a1b2c3 under gc.
  • Peak memory under own grows with iterations exactly as with the hand-written index loop.

🤖 Generated with Claude Code

Base automatically changed from tslang-181 to main November 24, 2026 13:45
…t each step (TSLANG 182)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 72ceeef into main Nov 24, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the tslang-182 branch November 24, 2026 14:29
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