Repository navigation
any to object type checks fields; own: literal with capturing arrows given to an object type (spec 66) - #734
Merged
Merged
Conversation
`<{ 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>
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.
Two fixes from the open-items list.
A cast from
anyto an object type checks the tuple's fields.<{ n: number }>xchecked 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 weren. The cast now throws.TYPE_DESCR_RESERVED, nowTYPE_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.ts.IsTupleOfLayout, compares the box's id with the type's, and___check_tuplethrows "the object's fields are not those of type '…'".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:chainOf), not the cast.own_literal_captures, under own, rc, gc and none..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