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

Using lambdas in JsOverlay methods produces 'lambda$0 is not a function' error #9354

Closed
vtsaplin opened this issue May 31, 2016 · 2 comments
Closed
Assignees
Milestone

Comments

@vtsaplin
Copy link

When using lambdas in overlay methods in native JsTypes I am getting this error:

SEVERE: (TypeError) : $wnd.GoldenLayout.lambda$0 is not a function
com.google.gwt.core.client.JavaScriptException: (TypeError) : $wnd.GoldenLayout.lambda$0 is not a function

This method works:

    @JsOverlay
    public static final void test1() {
        int[] a = new int[1];
        Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
            @Override
            public void execute() {
                a[0] = 2;
            }
        });
    }

But this doesn't:

    @JsOverlay
    public static final void test2() {
        int[] a = new int[1];
        Scheduler.get().scheduleDeferred(() -> a[0] = 2);
    }

@jnehlmeier jnehlmeier added this to the 2.8 milestone May 31, 2016
@rluble rluble self-assigned this May 31, 2016
@rluble
Copy link
Contributor

rluble commented Jun 1, 2016

code review at https://gwt-review.googlesource.com/#/c/15020/

@rluble
Copy link
Contributor

rluble commented Jun 1, 2016

The issue here is that lambdas are implemented in the following way. The code for the lambda function is implemented by a static method in the declaring class and then the lambda itself is an anonymous inner class where the SAM method delegates to the static method in the declaring class.

When the declaring class is Native such method is defined in an inconsistent way. The fix in the current review is marking that method as a JsOverlay but this is far from ideal. A better implementation would be to define the static method in the anonymous inner class itself.

@rluble rluble closed this as completed Jun 2, 2016
hpehl pushed a commit to hpehl/gwt that referenced this issue Jun 8, 2016
The fix is a bit of a hack, a better solution would be
not to mimic the placement of the lambda implematation
by JDT, which is done that way out of necesity (as
lambdas are created dynamically via a factory), and
instead synthesize the method in the anonymous inner
class that is already synthesized to represent the
lambda in GWT.

Bug: gwtproject#9354
Bug-Link: http://github.com/gwtproject/gwt/issues/9354
Change-Id: I749c5ef1356ae5e0ec6a8f2dcabbaa15e4001f9a
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

3 participants