HaxeFoundation / HaxeFoundation/haxe
[JS] Generated closure leads to a runtime exception
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
Haxe 4.3.6.
This example is a bit nonsensical, real-world code makes sense, I just pared it down into a small example where the issue can be reproduced.
```haxe filename=src/Test.hx
package;
using Lambda;
class Test {
static final list = [ 1, 2, 3 ];
static function main() {
trace([ 5, 6, 4 ].exists(list.contains));
}
}
```
```hxml filename=build.hxml
-D no-inline
-cp src
-main Test
-js bin/test.js
--cmd node bin/test.js
```
The following code compiles (when using `-D no-inline`), becoming:
```js
...
console.log("src/Test.hx:9:",Lambda.exists([5,6,4],($_=Test.list,$bind($_,$_.contains))));
...
```
The `$_` refers to a (JS) array, which doesn't have the `contains` function (JS uses `includes` for the same thing), therefore `$_.contains` is null and the generated binding (`f`) is faulty. The code fails at runtime with this error:
_TypeError: f is not a function_
Contributor guide
Assessment
This issue has not been assessed yet.