Skip to content

Compiler generates invalid forwarders for @static fields #1223

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

Closed
lrytz opened this issue Apr 18, 2016 · 1 comment
Closed

Compiler generates invalid forwarders for @static fields #1223

lrytz opened this issue Apr 18, 2016 · 1 comment

Comments

@lrytz
Copy link
Member

lrytz commented Apr 18, 2016

import annotation.static
class T
object T { @static val ff = 10 }

produces an invalid forwarder method in T.class:

public class T {
  public static ff()I
    GETSTATIC T$.MODULE$ : LT$;
    INVOKEVIRTUAL T$.ff ()I
    IRETURN
}

In T$.class we have

public final class T$ {
  private final static I ff$$local

  public static ff()I
    GETSTATIC T$.ff$$local : I
    IRETURN
}

Accordingly, the following Java file compiles:

public class A {
  public static void main(String[] args) {
    System.out.println(T.ff());
  }
}

but fails at runtime: with Exception in thread "main" java.lang.IncompatibleClassChangeError: Expecting non-static method T$.ff()I

invoking T$.ff() from Java works, but is not as expected.

Also note that the field is private, name-mangled and in the module class. IUC, the SIP says that a public static should be generated in the companion class (not the module class), and it should not be name-mangled to support java interop.

@DarkDimius
Copy link
Contributor

Fixed in #1226

@odersky odersky closed this as completed Jul 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants