Skip to content
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

wasm-validator error when using anonymous functions #954

Closed
DuncanUszkay1 opened this issue Nov 14, 2019 · 3 comments
Closed

wasm-validator error when using anonymous functions #954

DuncanUszkay1 opened this issue Nov 14, 2019 · 3 comments

Comments

@DuncanUszkay1
Copy link
Contributor

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

@MaxGraey
Copy link
Member

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

@MaxGraey
Copy link
Member

MaxGraey commented Nov 14, 2019

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

@MaxGraey
Copy link
Member

MaxGraey commented Nov 18, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants