Closed
Description
Hello!
So I noticed another thing weird with Object literals. If I try to pass a class into my init object, to construct my other class. Everything works fine, but when everything is done, the runtime will throw a memory error.
Here is the test case code:
import {Console} from "as-wasi";
class OtherClass {
stuff: i32;
constructor(newStuff: i32) {
this.stuff = newStuff;
}
}
class MyClassInit {
otherClass: OtherClass;
}
class MyClass {
_myParam: i32;
_otherClass: OtherClass;
constructor(param: i32, init: MyClassInit) {
this._myParam = param;
this._otherClass = init.otherClass;
}
toString(): string {
return this._otherClass.stuff.toString();
}
}
export function _start(): void {
// Make our Other class
let otherClass = new OtherClass(24);
// Pass to my class as an object literal
let myClass = new MyClass(2424, {
otherClass: otherClass
});
// This will all work
Console.log("Logging myClass.toString() ...\n");
Console.log(myClass.toString());
Console.log("\n");
// Will Error on Exit
// ~lib/rt/pure.ts:122:13: error: null
}
Here is a reproducable test case: https://github.com/torch2424/as-playground/tree/master/object-literal-pass-instance
cc @dcodeIO or @MaxGraey , if you can point me to where this would be fixed in the compiler (would this object literal be fixed in the same place as #1229 ), I can make this fix 😄
Screenshot
Metadata
Metadata
Assignees
Labels
No labels