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

[JS] Generated closure leads to a runtime exception #11941

Open
gene-pavlovsky opened this issue Jan 24, 2025 · 0 comments
Open

[JS] Generated closure leads to a runtime exception #11941

gene-pavlovsky opened this issue Jan 24, 2025 · 0 comments

Comments

@gene-pavlovsky
Copy link

gene-pavlovsky commented Jan 24, 2025

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.

package;

using Lambda;

class Test {
  static final list = [ 1, 2, 3 ];

  static function main() {
    trace([ 5, 6, 4 ].exists(list.contains));
  }
}
-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:

...
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

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

No branches or pull requests

1 participant