-
-
Notifications
You must be signed in to change notification settings - Fork 158
fix(hir): stash class captures after a super() that is not its own statement
#8924
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
Merged
+400
−7
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,9 @@ | ||
| Place a derived class's early capture stash (`this.__perry_cap_* = param`) | ||
| after the statement that completes `super()` even when the call is not its own | ||
| statement — a minifier's `super(a), this.x = b, …` comma sequence (split so | ||
| the stash sits right after the call), an `if (super(), …)` test, or a `try`. | ||
| The stash used to fall back to constructor entry, which #8643's derived-`this` | ||
| TDZ turned into `ReferenceError: Must call super constructor in derived class | ||
| before accessing 'this' or returning from derived constructor` at every | ||
| construction — Coop's Next.js App Route fixture died at module init on | ||
| `new AppRouteRouteModule({…})` (refs #8546, #8882). |
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.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Place the early stash at the nested
super()execution point.early_capture_stash_slotreturns the position after the enclosing top-level statement. Forif (flag) { super(); this.value = this.read(); },read()runs aftersuper()but before the stash. Its capture field is unset, so it can read the stale declaration snapshot instead of the constructor's live capture parameter.return super()also remains invalid because the before-return stash accessesthisbefore the return expression evaluatessuper().crates/perry-hir/src/lower_decl/class_captures.rs#L648-L650: insert the early stash into the nested branch or expression sequence immediately aftersuper(). Do not use an enclosing-statement boundary for this case.crates/perry-hir/src/lower_decl/class_captures.rs#L681-L681: excludereturn super()from this insertion path, or transform it sosuper()completes before any generatedthisaccess.crates/perry-hir/src/lower/tests.rs#L1707-L1744: assert recursive ordering for a branch that invokes a captured instance method immediately aftersuper().crates/perry/tests/derived_ctor_capture_stash_after_super.rs#L95-L121: add an end-to-end fixture where a nested branch calls such a method aftersuper()and after the captured outer value changes.📍 Affects 3 files
crates/perry-hir/src/lower_decl/class_captures.rs#L648-L650(this comment)crates/perry-hir/src/lower_decl/class_captures.rs#L681-L681crates/perry-hir/src/lower/tests.rs#L1707-L1744crates/perry/tests/derived_ctor_capture_stash_after_super.rs#L95-L121🤖 Prompt for AI Agents