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

Error when using a lambda which works when replaced with anonymous class #52

Closed
vegegoku opened this issue May 27, 2019 · 2 comments
Closed
Assignees
Labels

Comments

@vegegoku
Copy link

Describe the bug
I have a certain implementation that where i am initializing a field using lambda as the following form

private SenderSupplier senderSupplier = new SenderSupplier(() -> new RequestSender<R, S>() {
    });

which fails the j2cl compilation, when i change the implementation to use anonymous class it works.

private SenderSupplier senderSupplier = new SenderSupplier(new Supplier<RequestRestSender>() {
        @Override
        public RequestRestSender get() {
            return new RequestSender<R, S>() {
            };
        }
    });

To Reproduce
I have a fork of this j2cl repository in which the bug is reproducible here

https://github.com/vegegoku/j2cl

the bug is reproduced in the j2cl hello World sample

$ cd j2cl/samples/helloworld
$ bazel build src/main/java/com/google/j2cl/samples/helloworld:helloworld

The exception

DEBUG: Rule 'io_bazel_rules_closure' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "bb2e546beaeeb7d69bf5d5fbde94efcb8ae216b6d585942e02cfea7f8609747c"
DEBUG: Rule 'bazel_skylib' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "bce240a0749dfc52fab20dce400b4d5cf7c28b239d64f8fd1762b3c9470121d8"
DEBUG: Rule 'com_google_protobuf' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "9510dd2afc29e7245e9e884336f848c8a6600a14ae726adb6befdb4f786f0be2"
DEBUG: Rule 'org_gwtproject_gwt' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "f081f0c1f4f31a8be012c5d479777db13d01db5c8c73edf6a8800d9458b7b553"
INFO: Analysed target //src/main/java/com/google/j2cl/samples/helloworld:helloworld (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /mnt/CODE/GIT/J2CL/j2cl/samples/helloworld/src/main/java/com/google/j2cl/samples/helloworldlib/BUILD:12:1: Transpiling to JavaScript //src/main/java/com/google/j2cl/samples/helloworldlib:helloworldlib failed: Worker process did not return a WorkResponse:

---8<---8<--- Start of log snippet, file at /home/vegegoku/.cache/bazel/_bazel_vegegoku/c180e8a0f82bbd4569c981778e99438b/bazel-workers/worker-10-J2cl.log ---8<---8<---
[... truncated ...]
e)
        at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source)
        at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
        at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
        at java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source)
        at java.base/java.util.stream.ReferencePipeline.collect(Unknown Source)
        at com.google.j2cl.ast.AstUtils.clone(AstUtils.java:672)
        at com.google.j2cl.ast.MethodCall.clone(MethodCall.java:97)
        at com.google.j2cl.ast.MethodCall.clone(MethodCall.java:29)
        at com.google.j2cl.ast.AstUtils.lambda$clone$0(AstUtils.java:672)
        at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
        at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source)
        at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
        at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
        at java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source)
        at java.base/java.util.stream.ReferencePipeline.collect(Unknown Source)
        at com.google.j2cl.ast.AstUtils.clone(AstUtils.java:672)
        at com.google.j2cl.ast.visitors.NormalizeConstructors$2.rewriteNewInstance(NormalizeConstructors.java:330)
        at com.google.j2cl.ast.visitors.NormalizeConstructors$2.rewriteNewInstance(NormalizeConstructors.java:321)
        at com.google.j2cl.ast.AbstractRewriter.postProcessNewInstance(AbstractRewriter.java:987)
        at com.google.j2cl.ast.Visitor_NewInstance.visit(Visitor_NewInstance.java:16)
        at com.google.j2cl.ast.NewInstance.accept(NewInstance.java:82)
        at com.google.j2cl.ast.Visitor_BinaryExpression.visitMembers(Visitor_BinaryExpression.java:36)
        at com.google.j2cl.ast.Visitor_BinaryExpression.visit(Visitor_BinaryExpression.java:14)
        at com.google.j2cl.ast.BinaryExpression.accept(BinaryExpression.java:110)
        at com.google.j2cl.ast.Visitor_ExpressionStatement.visitMembers(Visitor_ExpressionStatement.java:33)
        at com.google.j2cl.ast.Visitor_ExpressionStatement.visit(Visitor_ExpressionStatement.java:14)
        at com.google.j2cl.ast.ExpressionStatement.accept(ExpressionStatement.java:46)
        at com.google.j2cl.ast.VisitorUtils.visitList(VisitorUtils.java:28)
        at com.google.j2cl.ast.Visitor_Block.visitMembers(Visitor_Block.java:32)
        at com.google.j2cl.ast.Visitor_Block.visit(Visitor_Block.java:14)
        at com.google.j2cl.ast.Block.accept(Block.java:53)
        at com.google.j2cl.ast.Visitor_Method.visitMembers(Visitor_Method.java:37)
        at com.google.j2cl.ast.Visitor_Method.visit(Visitor_Method.java:14)
        at com.google.j2cl.ast.Method.accept(Method.java:156)
        at com.google.j2cl.ast.VisitorUtils.visitList(VisitorUtils.java:28)
        at com.google.j2cl.ast.Visitor_Type.visitMembers(Visitor_Type.java:39)
        at com.google.j2cl.ast.Visitor_Type.visit(Visitor_Type.java:14)
        at com.google.j2cl.ast.Type.accept(Type.java:324)
        at com.google.j2cl.ast.VisitorUtils.visitList(VisitorUtils.java:28)
        at com.google.j2cl.ast.Visitor_CompilationUnit.visitMembers(Visitor_CompilationUnit.java:36)
        at com.google.j2cl.ast.Visitor_CompilationUnit.visit(Visitor_CompilationUnit.java:14)
        at com.google.j2cl.ast.CompilationUnit.accept(CompilationUnit.java:83)
        at com.google.j2cl.ast.visitors.NormalizeConstructors.rewriteNewInstances(NormalizeConstructors.java:320)
        at com.google.j2cl.ast.visitors.NormalizeConstructors.applyTo(NormalizeConstructors.java:123)
        at com.google.j2cl.transpiler.J2clTranspiler.normalizeUnits(J2clTranspiler.java:256)
        at com.google.j2cl.transpiler.J2clTranspiler.transpileImpl(J2clTranspiler.java:134)
        at com.google.j2cl.transpiler.J2clTranspiler.lambda$transpile$0(J2clTranspiler.java:107)
        at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)
---8<---8<--- End of log snippet, 2957 chars omitted ---8<---8<---
Target //src/main/java/com/google/j2cl/samples/helloworld:helloworld failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.269s, Critical Path: 0.09s
INFO: 2 processes: 1 local, 1 worker.
FAILED: Build did NOT complete successfully

Bazel version

WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown".
Build label: 0.24.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Mar 26 16:12:02 2019 (1553616722)
Build timestamp: 1553616722
Build timestamp as int: 1553616722

Expected behavior
I expect the code with the lambda to transpile successfully.

@rluble rluble self-assigned this May 28, 2019
@rluble rluble added the bug label May 28, 2019
@rluble
Copy link
Collaborator

rluble commented May 28, 2019

Thanks for the clear repro.

I'll have a look tomorrow. Could you check if using Supplier<RequestRestSender> or Supplier<RequestRestSender<T, S>> instead the raw type as a type parameter in Supplier in the contructor of SenderSupplier also triggers the error?

@vegegoku
Copy link
Author

vegegoku commented May 28, 2019

Adding the generic types to the SenderSupplier then using this form works

private SenderSupplier<R,S> senderSupplier = new SenderSupplier<>(() -> new RequestSender<R,S>() {
    });

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

No branches or pull requests

2 participants