Skip to content

BREAKING CHANGE: Make class fields a special kind of property #2548

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
wants to merge 14 commits into from

Conversation

dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented Nov 4, 2022

Removes the hard distinction between fields, i.e.

class Foo {
  a: i32;
}

and properties, i.e.

class Foo {
  get a(): i32 { return 42; }
  set a(value: i32) { }
}

by making fields special kinds of properties, differing in having an associated memory offset. As a result, fields (which get built-in getters and setters) and properties (with explicit getters and setters) can override each other, lifting the annoying limitation that interface fields can only be implemented with properties. Since interchangeable fields and properties are more powerful than what is possible in JS/TS, compatibility with TS becomes a matter of disallowing what wouldn't be supported there due to JS nature.

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

dcodeIO added a commit to AssemblyScript/website that referenced this pull request Nov 6, 2022
that also work with interfaces
@dcodeIO
Copy link
Member Author

dcodeIO commented Nov 6, 2022

Last commit bakes in static instanceof helpers for both classes and interfaces that no longer rely on the RTTI blob. Together with host bindings that also generate static code, bundling the RTTI blob now is no longer necessary. I did not yet remove the RTTI blob, since doing so in turn renders the loader non-functional, so should likely get its own PR.

@dcodeIO dcodeIO marked this pull request as ready for review November 7, 2022 15:08
@dcodeIO dcodeIO changed the title Make class fields a special kind of property BREAKING CHANGE: Make class fields a special kind of property Nov 7, 2022
@dcodeIO
Copy link
Member Author

dcodeIO commented Nov 9, 2022

(for some reason this one doesn't show as merged as usual but is still open, so closing manually)

@dcodeIO dcodeIO closed this Nov 9, 2022
pull bot pushed a commit to ehtick/assemblyscript that referenced this pull request Nov 9, 2022
BREAKING CHANGE: Element kinds FIELD and FIELD_PROTOTYPE and elements Field and FieldPrototype have been removed. Instead, Property inherit previous Field functionality, indicated by property.isField.
@dcodeIO dcodeIO mentioned this pull request Nov 10, 2022
2 tasks
dcodeIO added a commit to AssemblyScript/website that referenced this pull request Nov 11, 2022
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.

1 participant