Repository navigation
fix(wasm): a class without a constructor initializes its fields and runs its parent's #14616
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
Closed
Changes from all commits
Commits
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,5 @@ | ||
| `--target web`: a class that declares no constructor dropped its field | ||
| initializers (`class X { tag = "a" }` gave `new X().tag === undefined`), and a | ||
| derived class without one never ran its parent's constructor. Such a class now | ||
| gets the constructor TypeScript gives it: the parent's constructor runs with | ||
| the arguments, then the class's own field initializers. |
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
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.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Key the constructor plan by module-qualified class identity, not by bare class name.
The planner in
synthesized_ctorsbuilds its map fromclass.nameacross all modules. Two module-level classes with the same name in different modules collide. The later one replaces the earlier one. An earlier constructor-free class with field initializers then gets no synthesized constructor, so its initializers do not run. The lookup atcompile.rs:1372uses the same bare name, so the omission is silent.A fix needs a module-qualified key for both the planner map and the lookup. It also needs the matching
extends_nameresolution. Confirm the identity that the emitter can access before making this change. This change affects the whole constructor plan, so no localized diff is given here.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.
Correct that the plan is keyed by bare class name, but that is how the whole WASM emitter identifies classes today:
class_ctor_map,class_method_map,class_parent_map(and the runtime'sclassMethodTable/classParentTable) are all keyed byclass.name, so two same-named classes in different modules already collide for constructors, methods andinstanceofbefore this PR.synthesized_ctorsfollows that existing identity rather than introducing a new collision. Moving the emitter to module-qualified class identity is a separate change across all of those tables; I would rather do it on its own (I can open an issue) than widen this one.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.
Analysis chain
Script executed:
Length of output: 38978
@ralicloYou’re right that class identity is a wider WASM limitation. I agree that a coordinated change can be handled separately.One distinction: a synthesized constructor can overwrite an earlier same-named declared constructor in
class_ctor_map(compile.rs, Line 793). The base revision registered only declared constructors, so the new registration can change which constructor runs.I’m not marking this finding as addressed, but I accept deferring the identity change.
You are interacting with an AI system.