Skip to content

Passing Instance through an Object Literal Causes a runtime error on exit #1272

Description

@torch2424

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

Screenshot from 2020-05-14 10-33-16

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions