fix(hir): language/expressions/object literal semantics test262 parity#4751
Merged
Conversation
Object-literal method definitions (`{ m([x,y]) {} }`, `{ m(a = 23) {} }`)
lowered their parameters without (1) destructuring-extraction statements or
(2) default-parameter fill statements. Plain functions and class methods both
do this; `lower_method_prop` (the object-literal method path) did not, so:
- bare destructuring params threw `ReferenceError: identifier is not defined`
(the bound names `x`, `y` never got a `Let`);
- default params read as `undefined` (object methods never dispatch through
the `__perry_wrap_<name>` prologue that applies a top-level function's
registered defaults, so the body must carry the `if (p === undefined)`
checks itself).
Fix mirrors `lower_decl/class_members.rs`: unwrap `Pat::Assign` to the inner
array/object pattern before the destructuring check (so `[x] = [1]` is
recognized), generate extraction `Let`s before lowering the body, then prepend
`build_default_param_stmts` so defaults run before destructuring.
test262 language/expressions/object: 453 -> 557 pass (+104), zero regressions
(two isolated runs each, identical). Fixes the sync `meth`/`gen-meth`/
`meth-dflt`/`gen-meth-dflt` destructuring + default families.
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.
Root cause
Object-literal method definitions (
{ m([x, y]) {} },{ m(a = 23) {} }) lowered their parameters incrates/perry-hir/src/lower/expr_object.rs(lower_method_prop) without:[x, y, z]never produced aLetforx/y/z, so the body threwReferenceError: identifier is not defined;__perry_wrap_<name>prologue that applies a top-level function's registered defaults, so without the body carrying its ownif (p === undefined) p = <default>checks, every defaulted param read asundefined.Plain functions (
lower_fn_decl/expr_function) and class methods (lower_decl/class_members.rs) already do both; the object-literal method path was the one site missing it.Fix
Mirror
lower_decl/class_members.rsexactly:Pat::Assignto the inner array/object pattern before theis_destructuring_patterncheck —[x] = [1]is aPat::Assignwrapping the pattern, so checking the rawparam.patmissed the defaulted-destructuring form.generate_param_destructuring_stmtsbefore lowering the body, so the destructured bindings are in scope when the body references them.build_default_param_stmtslast, so defaults run before destructuring (m([x] = [1]) {}).Files touched:
crates/perry-hir/src/lower/expr_object.rs(only).Results —
language/expressions/object453 → 557 pass (+104), zero regressions.
Measured with two isolated runs of both baseline (
origin/main@ 25ccfbb) and fix; both pairs were byte-identical (0 flaky), 0 tests that passed before now fail. Default compile path (no env flags).Fixed families (all the same root cause):
dstr/meth/gen-meth/async-gen-meth(+-dfltvariants) destructuring params — ~90 testsmethod-definition/meth-dflt-params/gen-meth-dflt-params/async-meth-dflt-paramsdefault-param edge casesscope-{,gen-}meth-param-*var-scope casesRemaining failures in the directory are unrelated (lone
eval(...)of string code,fn.namedescriptor edge cases,super-in-object-method, async-generatoryield*delegation).