Skip to content

any to object type checks fields; own: literal with capturing arrows given to an object type (spec 66) - #734

Merged
ASDAlexander77 merged 2 commits into
mainfrom
any-tuple-layout
Oct 29, 2026
Merged

ASDAlexander77 merged 2 commits into
mainfrom
any-tuple-layout

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Two fixes from the open-items list.

A cast from any to an object type checks the tuple's fields. <{ n: number }>x checked only that the box held a tuple. A tuple of other fields was then read in the type's layout: { n: 5 } holds an s32 and read as garbage, and { m: 1.5 } was read as if its field were n. The cast now throws.

  • Layout id: the type descriptor's reserved slot (TYPE_DESCR_RESERVED, now TYPE_DESCR_LAYOUT) holds a tuple's layout id: a hash of the text of its field names and types, so it matches across modules. Other types have 0.
  • Check: a new op, ts.IsTupleOfLayout, compares the box's id with the type's, and ___check_tuple throws "the object's fields are not those of type '…'".
  • Test: 00any_to_tuple, extended.

-mm=own: an object literal whose arrows capture, given to an object type (spec 66). For const o = { w: (x: number) => x * k }; apply(o) with an object-type parameter, own reported "'this value' borrows a field and cannot be stored". Now the call borrows the members:

  • Borrow passed on: a tuple given only to calls that keep none of it passes the borrow on to them.
  • Chain root: a field read through an object seen as its storage now has the object as its root (chainOf), not the cast.
  • No move: neither that cast nor such a tuple moves the object.
  • Test: own_literal_captures, under own, rc, gc and none.
  • Still open: a literal whose arrow captures a class object moves the object into the literal's .captured, so the object can't be used after it under own. A closure capturing the same object only borrows it.

Validation: ctest 6303/6303. DefaultLib release JIT: gc 181/181, rc and none 180 (1 skipped), own 170 (11 skipped).

🤖 Generated with Claude Code

ASDAlexander77 and others added 2 commits October 29, 2026 13:22
`<{ n: number }>x` checked only that the box held a tuple. A tuple of
other fields was read as the type's layout: `{ n: 5 }` holds an s32, read
as a number (garbage), and `{ m: 1.5 }` was read as if its field were `n`.

The descriptor's reserved slot is now TYPE_DESCR_LAYOUT: for a tuple, an
id of its fields' names and types (literal types and const tuples seen as
what they are stored as), hashed from text so it matches across modules;
0 otherwise. ts.IsTupleOfLayout compares a box's with the type's, and
___check_tuple throws "the object's fields are not those of type ...".

Test: 00any_to_tuple (s32 field, other field name, nested objects).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ype (spec 66)

`const o = { w: (x: number) => x * k }; apply(o)` for an object-type
parameter was "'this value' borrows a field and cannot be stored". The
cast reads each member out as a method bound to the literal and makes the
parameter's tuple of them; the call only borrows them.

- passesOn: a tuple given only to calls that keep none of it passes the
  borrow on to them.
- chainOf: a field read through an object seen as its storage has the
  object as its root (owned when made here), not the cast (owned by no
  one, so any call - the one given the tuple - might drop it).
- isBorrow: that cast, when only fields are reached through it, and such
  a tuple, move nothing.

Test: own_literal_captures (own, rc, gc, none). Still open: a literal
capturing an object moves it into `.captured`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit de59796 into main Oct 29, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the any-tuple-layout branch October 29, 2026 14:08
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