-
-
Notifications
You must be signed in to change notification settings - Fork 670
Allow duplicate fields #2158
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
Allow duplicate fields #2158
Conversation
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.
A few observations :)
fieldInstance.memoryOffset = memoryOffset; | ||
memoryOffset += fieldType.byteSize; | ||
if (existingField !== null) { | ||
fieldInstance.memoryOffset = existingField.memoryOffset; |
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.
I have a vague suspicion that this can lead to issues, since typically inherited fields share the same flow flags for example, which is not the case anymore when duplicating the field. I don't see a case right now where this would trigger for sure (perhaps field initialization checks in ctors, hmm), though, but leaving a note here in case we ever encounter something along those lines.
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.
Would you like me to insert some sort of comment there?
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.
I guess it's fine without, just wanted to leave the note so you and me are aware in case :)
Thank you! |
Turns out that covariance on class fields as introduced here in unsound and is rejected by Wasm GC. Means we'll likely have to revert this. See PR linked above for details. |
What's this?
This PR replaces the "duplicate identifier" diagnostic used in the
markVirtuals
function (which also doesn't catch private duplicate fields) with a few checks in thefinishResolveClass
function for visibility and assignability, conforming to TS.I also implemented ambient fields, or fields with thedeclare
keyword.What does this allow?
This allows, in general, duplicate fields, but also allows duplicate fields that are assignable to the respective field in the base class
In the end, this feature was implemented in order to allow the
VariableDeclaration
class to upgrade itsname
field from anIdentifierExpression
to anExpression
; this allows array destructuring to be implemented cleanly.