Skip to content
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

2.12 emits static forwarder for bridge method in mirror class #10812

Closed
lrytz opened this issue Apr 4, 2018 · 4 comments
Closed

2.12 emits static forwarder for bridge method in mirror class #10812

lrytz opened this issue Apr 4, 2018 · 4 comments
Assignees
Milestone

Comments

@lrytz
Copy link
Member

lrytz commented Apr 4, 2018

trait A { def f: Object = null }
object B extends A { override def f: String = "b" }

With 2.12.5, asm gives

  // access flags 0x9
  public static f()Ljava/lang/String;
    GETSTATIC B$.MODULE$ : LB$;
    INVOKEVIRTUAL B$.f ()Ljava/lang/String;

  // access flags 0x9
  public static f()Ljava/lang/Object;
    GETSTATIC B$.MODULE$ : LB$;
    INVOKEVIRTUAL B$.f ()Ljava/lang/Object;

In 2.11, we don't get the static forwarder for the bridge method. Luckily, javac picks one of the two (the more specific), but IntelliJ seems to complain.

https://discuss.lightbend.com/t/http-get-is-ambiguous-from-java/571/12

@lrytz lrytz self-assigned this Apr 4, 2018
@lrytz
Copy link
Member Author

lrytz commented Apr 16, 2018

Turns out this is an older bug, also in 2.11. Making A a class instead of a trait:

class A { def f: Object = null }
object B extends A { override def f: String = "b" }

Gives two static forwarders in B.class.

The difference in 2.12 is: if A is a trait, in 2.11, method A.f is abstract, and no forwarder is added. In 2.12 (with default methods), A.f is concrete, and a frowarder is added.

We use this for member lookup (simplified of real):

scala> enteringJVM(symbolOf[B.type].info.membersBasedOnFlags(reflect.internal.Flags.BRIDGE, reflect.internal.Flags.METHOD)).filter(_.name.toString == "f").foreach(s => println((s, s.info, s.owner, s.debugFlagString)))
(method f,=> String,object B,<method> override)
(method f,=> Object,class A,<method> <triedcooking>)

@lrytz
Copy link
Member Author

lrytz commented Apr 16, 2018

Seems I can just do the member lookup in an earlier phase where we don't have bridges yet.

@SethTisue
Copy link
Member

scala/scala#6531

@SethTisue SethTisue added this to the 2.13.0-M4 milestone Apr 17, 2018
@johanandren
Copy link

Yay, thank you!

@SethTisue SethTisue modified the milestones: 2.13.0-M4, 2.12.7 Apr 17, 2018
@xuwei-k xuwei-k added the jdk11 label Aug 10, 2018
eed3si9n added a commit to eed3si9n/scala that referenced this issue Aug 11, 2018
Fixes scala/bug#11061
Ref scala/bug#10812

On 2.13.x branch scala#6531 removed the forwarder for bridge methods. I would like to do same in 2.12.x since Java 11-ea started to find them ambiguous as seen in akka/akka#25449 / scala/bug#11061.

To keep binary compatibility, I am still emitting the forwarder for bridge methods, but with `ACC_BRIDGE` flag.
eed3si9n added a commit to eed3si9n/scala that referenced this issue Aug 20, 2018
Fixes scala/bug#11061
Ref scala/bug#10812

On 2.13.x branch scala#6531 removed the mirror class forwarders for bridge methods. I would like to do same in 2.12.x since Java 11-ea started to find them ambiguous as seen in akka/akka#25449 / scala/bug#11061.

To keep binary compatibility, I am still emitting the forwarders for bridge methods, but with `ACC_BRIDGE` flag.
eed3si9n added a commit to eed3si9n/scala that referenced this issue Aug 20, 2018
Fixes scala/bug#11061
Ref scala/bug#10812

On 2.13.x branch scala#6531 removed the mirror class forwarders for bridge methods. I would like to do same in 2.12.x since Java 11-ea started to find them ambiguous as seen in akka/akka#25449 / scala/bug#11061.

To keep binary compatibility, I am still emitting the forwarders for bridge methods, but with `ACC_BRIDGE` flag.
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

4 participants