fix(codegen): apply ctor return-override on standalone-symbol new path (#5345)#5388
fix(codegen): apply ctor return-override on standalone-symbol new path (#5345)#5388proggeramlug wants to merge 1 commit into
Conversation
#5345) `new Derived()` for a class with its own constructor takes the shared `<class>_constructor` symbol-call path (the default since the [#bloat] change; `force_ctor_call`). That path called the standalone constructor but discarded its return value and yielded the freshly-allocated `this`, so ECMAScript constructor return-override semantics were never applied: - a derived ctor returning a non-object primitive did NOT throw the required TypeError (`new Derived(){ super(); return 0 }` silently returned the instance), and - a ctor returning an object did NOT override `this`. The standalone symbol already returns the body's explicit `return <value>` (or NaN-boxed `undefined` on fall-through), so the fix is to apply `js_ctor_return_override(this, ret, is_derived)` at the construction site — exactly as the inline `new` path already does — and return its result. `is_derived` mirrors the inline path's heritage check. test262 language/statements/class/subclass: +10 cases (parity 31.2% → 40.4%), 0 regressions — the full `derived-class-return-override-with-*` cluster (boolean/null/number/string/symbol/object), the `-catch`/ `-catch-super`/`-catch-super-arrow` uncatchable-TypeError variants, and `class-definition-null-proto-contains-return-override`. The language/statements/class/definition dir is unchanged (no regressions). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesConstructor Return-Override Propagation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
Comment |
|
Closing as a duplicate. While I was working on this, #5386 (commit 9d76a29) landed on |
Summary
Fixes part of #5345 (test262 class tail).
new Derived()for a class with its own constructor takes the shared<class>_constructorsymbol-call path (the default since the[#bloat]change —force_ctor_callinlower_new). That path called the standalone constructor but discarded its return value and yielded the freshly-allocatedthis, so ECMAScript constructor return-override semantics ([[Construct]] step 13) were never applied:TypeError—class D extends B { constructor(){ super(); return 0 } }; new D()silently returned the instance instead of throwing; andthis.The standalone symbol already returns the body's explicit
return <value>(or NaN-boxedundefinedon fall-through), so the fix appliesjs_ctor_return_override(this, ret, is_derived)at the construction site — exactly as the inlinenewpath already does — and returns its result.is_derivedmirrors the inline path's heritage check (extends/extends_name/native_extends/extends_expr).Because the override runs at the construction site (outside any
tryin the body), a derived ctor'stry { return 0; } catch {}still throws an uncatchableTypeError, per spec.Verification
test262
language/statements/class/subclass(scripts/test262_subset.py, node v26):+10 fixed, 0 regressions. The fixed cases are the full
derived-class-return-override-with-*cluster (boolean / null / number / string / symbol / object), the-catch/-catch-super/-catch-super-arrowuncatchable-TypeError variants, andclass-definition-null-proto-contains-return-override.language/statements/class/definitionis byte-identical before/after (no regressions). Direct spot-checks confirm: derivedreturn 0→ throwsTypeError; derivedreturn {obj}→ overrides; derivedreturn;→this; basereturn 5→ primitive ignored (this).🤖 Generated with Claude Code
Summary by CodeRabbit