jsweet icon indicating copy to clipboard operation
jsweet copied to clipboard

Internal transpiler error during transpiling JGraphT

Open tinca opened this issue 5 years ago • 2 comments

Hi, My previous experiment and problem report with lambda and method reference comes from an experiment aiming at a possible transpilation of the excellent JGraphT lib. The first problem can be solved by modfication of the original source, which is presumably doable.

Now, transpilation revealed another issue. Transpilation failes with 2 errors, both at Queue.remove() method calls on LinkedList and ArrayDeque implementations. I tried looking into the docs and Collections test for hint to no avail.

A simple test shows the case:

public class MyQueue {
     Queue<String> queue = new LinkedList<>();

    public void remove() {
        String aString = "asdas";
        queue.add(aString);
        queue.remove();
    }
}

Without remove() it transpiles.

internal transpiler error at /Users/zkuti/projects-new/jsweet-quickstart/src/main/java/quickstart/MyQueue.java(14) dumping transpiler's strack trace: [JCMethodInvocation] queue.remove(... (/Users/zkuti/projects-new/jsweet-quickstart/src/main/java/quickstart/MyQueue.java:14) [JCExpressionStatement] queue.remove()... (/Users/zkuti/projects-new/jsweet-quickstart/src/main/java/quickstart/MyQueue.java:14) [JCBlock] {... (/Users/zkuti/projects-new/jsweet-quickstart/src/main/java/quickstart/MyQueue.java:11) [JCMethodDecl] public void remove() {... (/Users/zkuti/projects-new/jsweet-quickstart/src/main/java/quickstart/MyQueue.java:11) [JCClassDecl] public class MyQueue {... (/Users/zkuti/projects-new/jsweet-quickstart/src/main/java/quickstart/MyQueue.java:8) [JCCompilationUnit] package quickstart;... (/Users/zkuti/projects-new/jsweet-quickstart/src/main/java/quickstart/MyQueue.java:1) java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at com.sun.tools.javac.util.List.get(List.java:476) at org.jsweet.transpiler.model.support.MethodInvocationElementSupport.getArgument(MethodInvocationElementSupport.java:63) at org.jsweet.transpiler.extension.RemoveJavaDependenciesAdapter.substituteMethodInvocationOnArray(RemoveJavaDependenciesAdapter.java:1153) at org.jsweet.transpiler.extension.RemoveJavaDependenciesAdapter.substituteMethodInvocation(RemoveJavaDependenciesAdapter.java:250) at org.jsweet.transpiler.Java2TypeScriptTranslator.visitApply(Java2TypeScriptTranslator.java:3532) at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465) at org.jsweet.transpiler.util.AbstractTreeScanner.scan(AbstractTreeScanner.java:238) at com.sun.tools.javac.tree.TreeScanner.visitExec(TreeScanner.java:175) at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1296) at org.jsweet.transpiler.util.AbstractTreeScanner.scan(AbstractTreeScanner.java:238) at org.jsweet.transpiler.util.AbstractTreePrinter.print(AbstractTreePrinter.java:125) at org.jsweet.transpiler.Java2TypeScriptTranslator.printBlockStatement(Java2TypeScriptTranslator.java:2883) at org.jsweet.transpiler.Java2TypeScriptTranslator.printBlockStatements(Java2TypeScriptTranslator.java:2876) at org.jsweet.transpiler.Java2TypeScriptTranslator.visitMethodDef(Java2TypeScriptTranslator.java:2470) at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778) at org.jsweet.transpiler.util.AbstractTreeScanner.scan(AbstractTreeScanne

Any idea? Thanks!

tinca avatar Oct 07 '18 13:10 tinca

If you intend to port a whole Java library, you may to take a look at this: https://github.com/j4ts/j4ts

This is not my favourite way but you might get better results with it for an existing lib

lgrignon avatar Oct 07 '18 13:10 lgrignon

Thank you, I'll take a look at it.

In the meantime, do you think the above simple example is not worth a closer look?

tinca avatar Oct 07 '18 14:10 tinca