Skip to content

-mm=own: Array's [Symbol.iterator] says @borrows("this") - #47

Merged
ASDAlexander77 merged 1 commit into
mainfrom
own-array-iterators
Oct 27, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
own-array-iterators

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

Array's iterator<T>(this: T[]) ([Symbol.iterator]) returns this.values(), a generator that borrows the array under -mm=own. It now says @borrows("this"), as Map's entries()/keys() already do. The other models ignore it.

Depends on ASDAlexander77/TypeScriptCompiler#701 (a generator over its this parameter borrows it). Merge that first: before it, values() kept a copy of the array and @borrows("this") is refused.

Tests

  • With the compiler from #701 and DefaultLib rebuilt:
    • rc, gc and none pass every test.
    • own goes from 142 to 145/170: array_keys, array_values and array_iterator now pass, with no new failures.
  • Still failing under own: array_entries, because entries() yields [i, this[i]], a borrowed element in a tuple the caller owns.

🤖 Generated with Claude Code

It returns this.values(), which borrows the array. Needs the compiler's generator over a `this`
parameter borrowing it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 55f5367 into main Oct 27, 2026
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