Skip to content

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

Merged
merged 13 commits into from
Dec 2, 2021

Conversation

romdotdog
Copy link
Contributor

@romdotdog romdotdog commented Nov 28, 2021

  • I've read the contributing guidelines
  • I've added my name and email to the NOTICE file

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 the finishResolveClass function for visibility and assignability, conforming to TS. I also implemented ambient fields, or fields with the declare 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

class A {}
class B extends A {}

class A1 {
  constructor(public a: A) {}
}

class A2 extends A1 {
  constructor(public a: B) {
    super(a)
  }
}

In the end, this feature was implemented in order to allow the VariableDeclaration class to upgrade its name field from an IdentifierExpression to an Expression; this allows array destructuring to be implemented cleanly.

Copy link
Member

@dcodeIO dcodeIO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few observations :)

@romdotdog romdotdog requested a review from dcodeIO November 29, 2021 01:56
@romdotdog romdotdog requested a review from dcodeIO December 1, 2021 03:57
@romdotdog romdotdog mentioned this pull request Dec 1, 2021
2 tasks
fieldInstance.memoryOffset = memoryOffset;
memoryOffset += fieldType.byteSize;
if (existingField !== null) {
fieldInstance.memoryOffset = existingField.memoryOffset;
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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 :)

@dcodeIO dcodeIO merged commit a924cc7 into AssemblyScript:main Dec 2, 2021
@dcodeIO
Copy link
Member

dcodeIO commented Dec 2, 2021

Thank you!

@dcodeIO
Copy link
Member

dcodeIO commented Oct 16, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants