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

Method reference on a method with @Template generates invalid code #125

Open
npiguet opened this issue Dec 3, 2015 · 0 comments
Open

Method reference on a method with @Template generates invalid code #125

npiguet opened this issue Dec 3, 2015 · 0 comments

Comments

@npiguet
Copy link
Member

npiguet commented Dec 3, 2015

Right now, code like

Map<String, String> map = $map();
$array("a", "b", "c").$forEach(map::$delete);

would generate the following (obviously wrong) code:

var map = {};
["a", "b", "c"].forEach(stjs.bind(map, "$delete"));

The root cause of this is $delete is not really a method of Map (well, Map itself is not really a class to begin with...), but we use a clever @Template to make it look like it is. The method reference translation code is not @Template aware, and in this case there really isn't way to generate the corresponding code.

ST-JS should generate a compile-time error when a method reference is used on a method that carries an @Template annotation. It should also suggest the user to transform the method reference to a Lambda, which would solve the problem:

Map<String, String> map = $map();
$array("a", "b", "c").$forEach(i -> map.$delete(i));

would generate the following (now correct) code:

var map = {};
["a", "b", "c"].forEach(function(i){delete map[i];});
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