Closed
Description
Consider this code, nearly identical to the default code added when scaffolding a new project:
function add(a: i32, b: i32): i32 {
return a + b;
}
export {
add
};
It works just fine. However, in JavaScript it's often more idiomatic to assign a function to a const rather than using it directly. So I do:
const add = function add(a: i32, b: i32): i32 {
return a + b;
};
export {
add
};
And suddenly the compiler crashes, with the following backtrace:
▌ C:\[...]\node_modules\assemblyscript\std\portable\index.js:200
▌ throw new AssertionError(message);
▌ ^
▌
▌ AssertionError: assertion failed
▌ at null.q.assert (C:\[...]\node_modules\assemblyscript\std\portable\index.js:200:11)
▌ at Nr.toTypeScriptType (C:\[...]\node_modules\assemblyscript\src\bindings\tsd.ts:239:21)
▌ at Nr.visitGlobal (C:\[...]\node_modules\assemblyscript\src\bindings\tsd.ts:55:23)
▌ at Nr.visitElement (C:\[...]\node_modules\assemblyscript\src\bindings\util.ts:82:52)
▌ at Nr.visitFile (C:\[...]\node_modules\assemblyscript\src\bindings\util.ts:59:14)
▌ at Nr.walk (C:\[...]\node_modules\assemblyscript\src\bindings\util.ts:47:65)
▌ at Nr.build (C:\[...]\node_modules\assemblyscript\src\bindings\tsd.ts:189:10)
▌ at Function.build (C:\[...]\node_modules\assemblyscript\src\bindings\tsd.ts:37:41)
▌ at Module.JS (C:\[...]\node_modules\assemblyscript\src\index-wasm.ts:330:21)
▌ at Module.Ue (C:\[...]\node_modules\assemblyscript\cli\index.js:954:35)
Using an arrow function, as follows, crashes in the same way.
const add = (a: i32, b: i32): i32 => {
return a + b;
};
export {
add
};