AssemblyScript/assemblyscript

Transfer higher level data types like objects to extended class objects (host binding and inheritance)

QuisMagni opened this issue · 0 comments

Bug description

I would like to pass data from host to as using host bindings. On the as side the target class is extending another class.

Steps to reproduce

Target class:

export class Foo {
    a: i32 = 0
}

export class Baa extends Foo {
    b: i32 = 0
}

index.ts (AS)

export function test(test: Baa): void {
    console.log('test')
}

Calling from host side:

...
 wasm.test({a: 0, b: 1})
...

I get a runtime error like that:

Uncaught (in promise) TypeError: internref expected at __lowerInternref (release.js?t=1725378963979:80:11) at Object.test (release.js?t=1725378963979:37:14) ....
Generated glue code is not looking as expected:

declare namespace __AdaptedExports {
  /** Exported memory */
  export const memory: WebAssembly.Memory;
  /**
   * assembly/index/test
   * @param test `assembly/Baa`
   */
  export function test(test: __Internref16): void;
}
/** assembly/Baa */
declare class __Internref16 extends Number {
  private __nominal16: symbol;
  private __nominal17: symbol;
  private __nominal0: symbol;
}
/** Instantiates the compiled WebAssembly module with the given imports. */
export declare function instantiate(module: WebAssembly.Module, imports: {
  env: unknown,
}): Promise<typeof __AdaptedExports>;

Removing inheritance from target class is solving the problem:

export class Baa { a: i32 = 0 b: i32 = 0 }

Is inheritance not supported for host bindings?

AssemblyScript version

0.27.29