Repository navigation
Define a __proto__ field of a recursive value as its own property #9471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
illusionalsagacity
wants to merge
3
commits into
rescript-lang:master
from
illusionalsagacity:fix-proto-field-recursive-record
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
6e4590d
Define a __proto__ field of a recursive value as its own property
illusionalsagacity ed43f7a
Test __proto__ keys on recursive constructors, extensions and untagge…
illusionalsagacity d5f4943
Preserve undefined slots in recursive array-backed records
illusionalsagacity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Fix a record field renamed with `@as("__proto__")` (or a variant tag renamed with `@tag("__proto__")`) of a recursive value `let rec x = {...}`: it is now an own property of the value, as it is of a record literal, instead of being dropped, becoming the prototype, or throwing `Cyclic __proto__ value`. An optional field of a recursive value set to `None` is now left out, as it is of a record literal, instead of being an own property holding `undefined`. |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This omission also applies to array-backed records, although
Js_dumppreserves every array element, including optionalNonevalues (compiler/backend/js_dump.ml:929–930). For example,type rec t = {@as("0") next: t, @as("1") value?: int}withlet rec x = {next: x, value: ?None}now initializes onlyx[0], leaving the array length at 1 instead of 2. Optional fields before other elements instead become holes, changing array iteration and own-key behavior. Restrict the omission to object-backed records and retain explicitundefinedassignments for array slots.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Real. For
type rec t = {@as("0") next: t, @as("1") value?: int},let rec x = {next: x, value: ?None}omittedx[1] = undefined, leavingx.length === 1instead of2, and a leading?Noneleft index0as a hole.Fixed in db553ff (after rebasing onto
master):compile_recursive_letnow omits optionalUndefinedfields only for object-backed records (array = false), so array-backed records assign every slot asJs_dumpdoes for array literals. Regression tests inrecursive_record_proto_field_test.res(arrayOptionalNone,arrayLeadingNone,arrayOptionalComputed) checkArray.lengthandObject.hasOwnfor both trailing and leading?Noneslots. No other checked-in outputs change.