Assemblyscript: wasm-validator error when using anonymous functions

Created on 14 Nov 2019  路  3Comments  路  Source: AssemblyScript/assemblyscript

Here's my minimal example: when I follow the instructions here (https://docs.assemblyscript.org/quick-start) with a clean install and clean directory and use this as my index.ts I get a compiler error
index.ts:

// The entry file of your WebAssembly module.
@unmanaged
export class Foo {
  use_anon_function(fn: (value: i32) => i32): Array<i32> {
    return new Array<i32>();
  }
}

export function anon_test(bars: Foo, value: i32): i32 {
    let bar_ids = bars.use_anon_function((bar: i32) =>
      value
    );

    return bar_ids.length;
}

npm run asbuild output:

> @ asbuild /Users/duncanuszkay/src/github.com/Shopify/temp-delete
> npm run asbuild:untouched && npm run asbuild:optimized


> @ asbuild:untouched /Users/duncanuszkay/src/github.com/Shopify/temp-delete
> asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --sourceMap --validate --debug

[wasm-validator error in function $assembly/index/anon_test~anonymous|0] unexpected false: local.get index must be small enough, on
[i32] (local.get $1)
[wasm-validator error in function $assembly/index/anon_test~anonymous|0] unexpected false: local.get must have proper type, on
[i32] (local.get $1)
ERROR: Validate error
    at /Users/duncanuszkay/src/github.com/Shopify/temp-delete/node_modules/assemblyscript/cli/asc.js:573:25
    at measure (/Users/duncanuszkay/src/github.com/Shopify/temp-delete/node_modules/assemblyscript/cli/asc.js:880:3)
    at Object.main (/Users/duncanuszkay/src/github.com/Shopify/temp-delete/node_modules/assemblyscript/cli/asc.js:570:27)
    at Object.<anonymous> (/Users/duncanuszkay/src/github.com/Shopify/temp-delete/node_modules/assemblyscript/bin/asc:21:26)
    at Module._compile (internal/modules/cjs/loader.js:774:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
    at Module.load (internal/modules/cjs/loader.js:641:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)
    at internal/main/run_main_module.js:17:11

If I don't use the function argument inside the anon function it compiles:
index.ts

// The entry file of your WebAssembly module.
@unmanaged
export class Foo {
  use_anon_function(fn: (value: i32) => i32): Array<i32> {
    return new Array<i32>();
  }
}

export function anon_test(bars: Foo, value: i32): i32 {
    let bar_ids = bars.use_anon_function((bar: i32) =>
      100
    );

    return bar_ids.length;
}

Looks like I can't use function arguments inside anonymous functions? The error message given doesn't seem to be correlated though.

Let me know if you need any more info

duplicate question

Most helpful comment

@DuncanUszkay1 In next daily night build such closure cases will be fail earlier with "AS100: Not implemented." error instead "unknown" validation error

All 3 comments

Hi, closures not yet support. See similar questions / issues: #754, #661, #242, #173 and #798

@DuncanUszkay1 In next daily night build such closure cases will be fail earlier with "AS100: Not implemented." error instead "unknown" validation error

Since we emit proper "not implemented" error and we already have bunch of several issues relate to closure's issue I'm closing this. Plz watch for progress in #798

Was this page helpful?
0 / 5 - 0 ratings

Related issues

torch2424 picture torch2424  路  3Comments

blooddy picture blooddy  路  3Comments

emil14 picture emil14  路  3Comments

drachehavoc picture drachehavoc  路  6Comments

MaxGraey picture MaxGraey  路  4Comments