Repository navigation
An object literal's this-free arrows given for an object type are closures - #722
Merged
Merged
Conversation
…sures
`apply({ w: x => x + 1 })` for `apply(o: { w: (x: number) => number })`, or
`const o: { w: (x: number) => number } = { w: x => x * 2 }`, made `w` a
method taking the literal object as its `this`; read into the receiver's
function-typed field it became a hybrid_func bound to an object made by
ts.New that nothing released, which -mm=own rejected ("borrows a field and
cannot be stored, returned or captured").
An arrow function member that never says `this` or `super` (anywhere in it,
nested functions included; an arrow's `this` is its surroundings', and
00object_func3 relies on one reaching the literal through a nested
function's `this`) is now made in the literal's first pass as a closure in a
field, when the literal is made for an object (tuple) type: its receiver,
or a generic call's parameter (markClosureMembers). Its untyped parameters
take their types from the receiver's member, as a method's do. A literal
made for an interface, or with no receiver, keeps its members methods: it
may become an interface value, whose vtable is built from them.
Own spec section 60. Test own_literal_closures (own, rc, gc, none; own emits
no counting).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # tslang/docs/superpowers/specs/2026-09-24-own-memory-model-design.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
apply({ w: x => x + 1 })forapply(o: { w: (x: number) => number }), orconst o: { w: (x: number) => number } = { w: x => x * 2 }, compiledwas a method whosethisis the literal object. Read into the receiver's function-typed field, it became ahybrid_funcbound to an object made byts.Newthat nothing released.-mm=ownrejected every such call ("'this value' borrows a field and cannot be stored, returned or captured").Change (MLIRGen,
markClosureMembers). Some arrow members are now compiled in the literal's first pass as closures in fields, not as methods. That applies when both of these hold:thisorsuper, anywhere inside it, nested functions included. In TypeScript an arrow'sthisis its surroundings', and00object_func3relies on an arrow member's nested function reaching the literal throughthis, so those arrows stay methods;Untyped parameters take their types from the receiver's member, as a method's do.
A literal made for an interface, or with no receiver, keeps its members as methods: it may become an interface value, whose vtable is built from them.
00interface_type_tag_in_vtablereturns such a literal as aShape.Own spec §60. It follows §59, which #721 adds; whichever PR merges second will hit a small conflict at the end of the spec.
Test:
own_literal_closurescovers a typed local, a parameter, a generic call (f1<T, U>), with and without captures, and several members in one literal. It runs under own, rc, gc and none; own emits no counting.00object_literal_contextual_lambdastill compiles only outside own: itsfoo({ read: () => s, write: value => s = value + "!" })calls hand a function a closure that writes a captured string, which own refuses on purpose.Validated on Windows: ctest 6136/6136, and the default library's release tests pass under gc, rc, none and own.
🤖 Generated with Claude Code