cincheo / jsweet

A Java to JavaScript transpiler.
http://www.jsweet.org
Other
1.45k stars 160 forks source link

static member can't be seen from grandchild #410

Open gladclef opened 6 years ago

gladclef commented 6 years ago

In the following example, the GrandChild class can't use the Parent's static member helloWorld:

// Parent.java
public class Parent
{
    public static String helloWorld = "hello world!";
}

// Child.java
public class Child extends Parent
{
}

// GrandChild.java
public class GrandChild extends Child
{
    public static void main(String[] args)
    {
        System.out.println(helloWorld);
    }
}

This produces the following TypeScript (using AMD modules):

// Parent.ts
/* Generated from Java with JSweet 2.1.0-SNAPSHOT - http://www.jsweet.org */
export class Parent {
    public static helloWorld : string = "hello world!";
}
Parent["__class"] = "Parent";

// Child.ts
/* Generated from Java with JSweet 2.1.0-SNAPSHOT - http://www.jsweet.org */
import { Parent } from './Parent';

export class Child extends Parent {}
Child["__class"] = "Child";

// GrandChild.ts
/* Generated from Java with JSweet 2.1.0-SNAPSHOT - http://www.jsweet.org */
import { Child } from './Child';

export class GrandChild extends Child {
    public static main(args : string[]) {
        console.info(Parent.helloWorld);
    }
}
GrandChild["__class"] = "GrandChild";

GrandChild.main(null);

This results in the following error from the TypeScript compiler:

GrandChild.ts(6,22): error TS2552: Cannot find name 'Parent'. Did you mean 'parent'?

gladclef commented 6 years ago

I believe I have a fix for this here https://github.com/gladclef/jsweet/commit/0344a146dbd5c5cce506a13db7359704c7fb0d1d#diff-d23cc520db8641626d34a1b3805407ab and here https://github.com/gladclef/jsweet/commit/cf64d106748538d2f89a2da5ccae296bea246145#diff-d23cc520db8641626d34a1b3805407ab in this branch https://github.com/gladclef/jsweet/tree/fix-410-static-member-cant-be-seen-from-grandchild.

However, maybe I should wait until issue #403 is resolved because I messed up the git history, fixed it with revert, and that second link reverts my revert to add in the desired changes for this issue.

renaudpawlak commented 6 years ago

Hi! Sorry for delay but I don't have much time these days... and your problems seem complicated :( I will try to look at it over the weekend and I'll tell you what I can find out...

lgrignon commented 6 years ago

Now it's merged, do you want to PR again?