Repository navigation
[12.x] Evaluate a record spread's overrides in order - #9460
Open
illusionalsagacity wants to merge 2 commits into
Open
illusionalsagacity wants to merge 2 commits into
illusionalsagacity wants to merge 2 commits into
Conversation
…field as an own property (rescript-lang#9416) A record spread `{...base, f: v}` of a record with an optional field (or with 20 fields or more) is a copy of the base and assignments to it. The Lambda for the overrides set the last declared field first, so the overrides were evaluated in reverse order. The fields are now set in declaration order, followed by the later assignments in source order. For a field renamed with @as("__proto__") that the base does not have, the assignment to the copy ran the __proto__ setter it inherits from Object.prototype: an int was dropped and an object became the copy's prototype. A __proto__ field set on the copy right after it is made, as an override or by a later assignment, is now defined with Object.defineProperty, as an object literal would. Other names are still assigned, and an assignment elsewhere, x.p = v, is unchanged. 12.x always compiles a spread as a copy and assignments: it has no Lam_compile.try_compile_record_spread, which on master builds the object literal this PR makes wait for statements in the overrides. So the overrides' statements already run after the copy on 12.x, the literal and the dropped copy of a discarded result are not ported, and the __proto__ case is handled by Lam_compile.compile_copy_fields, which compiles the other fields as before. The order also changes the props of jsx_preserve_test's spread element to declaration order, as on master. 12.x has no source map project test, so that part of master's tests is left out, and master's test is reformatted with 12.x's formatter. (cherry picked from commit 83cf1de) Signed-off-by: Rob <illusionalsagacity@users.noreply.github.com>
This was referenced Dec 3, 2026
Member
|
#9513 made Could you drop the
I'll add the 12.x warning in a separate PR. This comment was drafted by Claude. |
Keep only the override-order fix from rescript-lang#9416, as requested on rescript-lang#9460: remove Js_exp_make.define_own_property, Lam_compile.compile_copy_fields, the __proto__ tests in record_spread_order_test, and the __proto__ part of the CHANGELOG entry. Signed-off-by: Rob <illusionalsagacity@users.noreply.github.com>
__proto__ field as an own property
Contributor
Author
|
Dropped the
|
This branch has not been deployed
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.
Backport of #9416 (override-order fix) to
maintenance/12.x.Problem
A record spread
{...base, f: v}of a record with an optional field (or with 20 fields or more) is compiled on 12.x as a copy of the base followed by assignments to it. The Lambda for the overrides set the last declared field first, so the overrides were evaluated in reverse order:Before:
After:
Fix
As on master:
Translcore.transl_recordsets the fields of the copy in declaration order, followed by the later assignments in source order.Differences from master:
Lam_compile.try_compile_record_spread. On master that function builds a spread as an object literal, which is what let an override's statements run before the base was copied; master's main fix makes it fall back to a copy and assignments. On 12.x a spread is always a copy and assignments, so the overrides' statements already run after the copy and that part doesn't apply. The literal form, and leaving out the copy of a discarded result or a throwing override, aren't ported either: they change only the shape of the output.__proto__part of Copy a record spread's base before overrides that need statements #9416 was dropped from this backport (since Reject __proto__ as the JavaScript name of a field #9513 removed it on master and rejected__proto__fields, and 12.x will deprecate them separately).jsx_preserve_test's element with spread props now lists its props in declaration order (className, thentitle), the same as on master.tests/project_tests/source_map, so master's source map test case is left out. Master's test file is reformatted with 12.x's formatter, and two of its comments that describe master's literal form are reworded.Tests
tests/tests/src/record_spread_order_test.resis master's test (without the__proto__cases). Without the fix, 5 of its 13 tests fail on 12.x: the order of several overrides, a copy that is bound and then used, pure statements after a call, a discarded result, and a throwing override. The only other checked-in output that changes isjsx_preserve_test.mjs.Investigated by Claude.