Skip to content

Implicitly inherit from Object #2559

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 7 commits into from
Nov 14, 2022
Merged

Implicitly inherit from Object #2559

merged 7 commits into from
Nov 14, 2022

Conversation

dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented Nov 12, 2022

Classes that are not unmanaged and don't extend other classes now implicitly extend Object. As a result, the type Object can be used to reference and pass along any normal class instance.

let obj: Object = new Anything();
function fn(arg: Object): void {
  if (arg instanceof Anything) {
    ...
  }
}
fn(new Anything());

Note: Does not apply to basic value types like i32, which are not objects.

With Object becoming the general base class, a breaking change to constant class ids was necessary, in that foundational classes move one up. Relevant for external integration with the runtime, where these ids may be hardcoded.

Class New id Old id
Object 0 dynamic
ArrayBuffer 1 0
String 2 1
...
  • I've read the contributing guidelines
  • I've added my name and email to the NOTICE file

CountBleck added a commit to CountBleck/assemblyscript-website that referenced this pull request Nov 12, 2022
The class IDs for ArrayBuffer and String have now been incremented by 1.
@dcodeIO dcodeIO marked this pull request as ready for review November 13, 2022 06:36
@jtenner
Copy link
Contributor

jtenner commented Nov 14, 2022

Thank you for this! I was able to test the branch with as-pect and it works after I made some coding changes. I also needed to use the new loader because the runtime type ids changed. Other than that, everything looks good to me!

@dcodeIO dcodeIO merged commit 688dcd2 into main Nov 14, 2022
dcodeIO pushed a commit to AssemblyScript/website that referenced this pull request Nov 14, 2022
@HerrCai0907 HerrCai0907 deleted the extend-object branch October 17, 2023 09:00
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