jsweet icon indicating copy to clipboard operation
jsweet copied to clipboard

Transpilation of JHeaps fails

Open tinca opened this issue 5 years ago • 7 comments

Hello,

It is a follow-up of this issue. I try to transpile JHeaps (the only dependency of JGraphT):

ts2js on org.jsweet.transpiler.TypeScript2JavaScriptWithTscTranspiler@407cd3 sourceFiles=56 launching tsc... org/jheaps/array/BinaryArrayAddressableHeap.ts(82,77): error TS1005: ',' expected. ',' expected at /Users/zkuti/projects-new/jheaps/src/main/java/org/jheaps/array/BinaryArrayAddressableHeap.java(217) org/jheaps/array/BinaryArrayAddressableHeap.ts(107,77): error TS1005: ',' expected. ',' expected at /Users/zkuti/projects-new/jheaps/src/main/java/org/jheaps/array/BinaryArrayAddressableHeap.java(266) org/jheaps/array/DaryArrayAddressableHeap.ts(126,77): error TS1005: ',' expected. ',' expected at /Users/zkuti/projects-new/jheaps/src/main/java/org/jheaps/array/DaryArrayAddressableHeap.java(254) org/jheaps/array/DaryArrayAddressableHeap.ts(154,77): error TS1005: ',' expected. ',' expected at /Users/zkuti/projects-new/jheaps/src/main/java/org/jheaps/array/DaryArrayAddressableHeap.java(313)

Neither --info or --debug option for grade reveals more. Though java.io.Serializable is used in the class' hierarchy removing them makes no difference.

Let me know if any more information needed. Thanks!

tinca avatar Oct 27 '18 11:10 tinca

You need to check what is wrong in the generated .ts code (see the lines indicated in the errors). From the code you should be able to analyse if it is a hard or easy problem to solve.

renaudpawlak avatar Oct 27 '18 12:10 renaudpawlak

Thanks for the hint. Is it possible that the cause is the use of java.lang.reflect.Array.newInstance in Java code? I have seen in the FAQ, that java.lang.reflect support is rather limited. Also, Intellij Idea can find supported TS constructs, but not this one.

tinca avatar Oct 27 '18 13:10 tinca

This is certainly not the problem. I've changed it to a non-reflection code, but the problem remained.

tinca avatar Oct 27 '18 14:10 tinca

Look at the tests in the 'reflect' folder to see what is actually supported. But from what I see from the error it looks like a syntax error in the generated code, which can be quite complicated to hunt down.

renaudpawlak avatar Oct 27 '18 16:10 renaudpawlak

I've made an example that demonstrates the problem where java to ts fails. Consider the following Java classes:

package quickstart;
public abstract class AbstractInnerGeneric<T> {
    class AnInner {}
}

package quickstart;
public class AnInnerGeneric<T> extends AbstractInnerGeneric<T> {
    public void aMethod() {
        AbstractInnerGeneric<T>.AnInner innerInstance = new AbstractInnerGeneric<T>.AnInner();
    }
}

The generated TS is:

namespace quickstart {
    export class AnInnerGeneric<T> extends quickstart.AbstractInnerGeneric<T> {
        public aMethod() {
            let innerInstance : quickstart.AbstractInnerGeneric<T>.AnInner = new quickstart.AbstractInnerGeneric<T>.AnInner(this.__parent);
        }
    }
    AnInnerGeneric["__class"] = "quickstart.AnInnerGeneric";
}

The line: let innerInstance : quickstart.AbstractInnerGeneric<T>.AnInner = new should be let innerInstance : quickstart.AbstractInnerGeneric.AnInner = new

Follow up: When I fix syntax for related ts files in my real project and use tsc command line (cut out from running gradle --debug) those errors go away, but dozens of others pop up instead.

tinca avatar Oct 30 '18 08:10 tinca

Can you confirm my finding?

tinca avatar Nov 02 '18 15:11 tinca

I have not tested but from what I can see in the code, I can confirm with enough confidence that your case is not supported yet. The process is to implement a minimal unit test from it and try to fix it. However since you code is using a lot inner classes, generics and abstract classes, it will be quite difficult to fix. :(

renaudpawlak avatar Nov 02 '18 16:11 renaudpawlak