cincheo / jsweet

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

enum and private variables. #660

Open arenevier opened 3 years ago

arenevier commented 3 years ago

Hi, the ts generated by the following code fails to compile:

public enum Bar {
  LOW {
    @Override
    public long value() {
      return ratio * 1L;
    }
  },
  MEDIUM {
    @Override
    public long value() {
      return ratio * 2L;
    }
  },
  HIGH {
    @Override
    public long value() {
      return ratio * 3L;
    }
  };

  private static final long ratio = 1L;

  public abstract long value();
}

with error Property 'ratio' does not exist on type 'typeof Bar'

Here is the problematic part of the generated ts:

export enum Bar {
    LOW, MEDIUM, HIGH
}

/** @ignore */
export abstract class Bar_$WRAPPER {

    ...

    static ratio = 1;

     ...
}

...

export namespace Bar {

    /** @ignore */
    export class Bar$0_$WRAPPER extends Bar_$WRAPPER {

        ...

        /**
         * 
         * @return {number}
         */
        public value(): number {
            return Bar.ratio * 1;
        }
    }
   .... 
}
lgrignon commented 3 years ago

Thanks for reporting