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

Emulation of Arrays triggers "unusable-by-js" warning #9592

Closed
jnehlmeier opened this issue Jan 25, 2018 · 4 comments
Closed

Emulation of Arrays triggers "unusable-by-js" warning #9592

jnehlmeier opened this issue Jan 25, 2018 · 4 comments
Milestone

Comments

@jnehlmeier
Copy link
Member

GWT version: HEAD and probably 2.8.2
Browser (with version): --
Operating System: --


Description

Compiling using GWT HEAD results in

Warnings in com/google/gwt/emul/java/util/Arrays.java
  [WARN] Line 1782: [unusable-by-js] Type of parameter 'd1' in 'int Arrays.1methodref$compare$Type.compare(long, long)' is not usable by but exposed to JavaScript.
  [WARN] Line 1782: [unusable-by-js] Type of parameter 'd2' in 'int Arrays.1methodref$compare$Type.compare(long, long)' is not usable by but exposed to JavaScript.
  [WARN] Suppress "[unusable-by-js]" warnings by adding a `@SuppressWarnings("unusable-by-js")` annotation to the corresponding member.

The code in question already has a @SuppressWarnings("unusable-by-js") annotation, so I guess the compiler does not see it because of the method reference.

  @JsFunction
  private interface CompareLongFunction {
    @SuppressWarnings("unusable-by-js")
    int compare(long d1, long d2);
  }

  private static CompareFunction getLongComparator() {
    return JsUtils.uncheckedCast((CompareLongFunction) Long::compare);
  }
@rluble
Copy link
Contributor

rluble commented Jan 25, 2018

The compiler builds the synthetic classes implementing lambdas upfront in GwtAstBuilder.java but does not propagate the suppressions.

The simplest reasonable solution is to blindly add unusable-by-js suppressions to synthetic methods. The reasoning being that the check will be performed for the functional interface nonetheless and the warning will be emitted there where the user wrote the offending code.

I'll gladly review the fix if anyone wants to tackle it.

There are two places in GwtAstBuilder where these are created:
1- for method references
https://gwt.googlesource.com/gwt/+/master/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java#1850
2- for lambdas
https://gwt.googlesource.com/gwt/+/master/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java#1252

JMethod has a fied that stores the suppressions.

@rluble
Copy link
Contributor

rluble commented Jan 25, 2018

Also the synthetic method is not marked as such. Another possible solution is to mark it as synthetic (which should be done nonetheless) and skip synthetic methods from being checked.

@axls
Copy link
Contributor

axls commented Jan 30, 2018

@tbroyer tbroyer added this to the 2.8.3 milestone Jan 30, 2018
hubot pushed a commit that referenced this issue Jan 31, 2018
Also this CL adds "synthetic" flag for lamda/method reference
synthetics.

Bug: #9592
Bug-Link: #9592
Change-Id: I86c0c252bd41c45bc45320e9516ae7541c83733d
@tbroyer
Copy link
Member

tbroyer commented Jan 31, 2018

Thanks @axls

@tbroyer tbroyer closed this as completed Jan 31, 2018
@tbroyer tbroyer modified the milestones: 2.8.3, 2.9 Apr 24, 2018
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

4 participants