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

Missing bridge method in trait when it has a covariant return type #22394

Open
XYZboom opened this issue Jan 17, 2025 · 0 comments
Open

Missing bridge method in trait when it has a covariant return type #22394

XYZboom opened this issue Jan 17, 2025 · 0 comments

Comments

@XYZboom
Copy link

XYZboom commented Jan 17, 2025

Compiler version

3.6.3-RC2

Minimized code

trait I0 {
  def func(): AnyRef
}

trait I1 extends I0 {
  override def func(): String = "123"
}

Output

Use javap -c -s- v I1 to check the bytecode: (Simplified it a bit)

  public static java.lang.String func$(I1);
    descriptor: (LI1;)Ljava/lang/String;
    flags: ACC_PUBLIC, ACC_STATIC

  public java.lang.String func();
    descriptor: ()Ljava/lang/String;
    flags: ACC_PUBLIC

Expectation

When I1 is written by Java, the output is:

  public java.lang.String func();
    descriptor: ()Ljava/lang/String;
    flags: ACC_PUBLIC

  public java.lang.Object func();
    descriptor: ()Ljava/lang/Object;
    flags: ACC_PUBLIC, ACC_BRIDGE, ACC_SYNTHETIC
}

Note that java does not generate static method func$ here. But scalac misses a bridge method here.

Further bug: java.lang.AbstractMethodError when implements I1 with a Java class

trait I0 {
  def func(): AnyRef
}

trait I1 extends I0 {
  override def func(): String = "123"
}
object Main {
  def main(args: Array[String]): Unit = {
    val i0: I0 = A()
    println(i0.func())
  }
}
// Java file
public class A implements I1 {
}
Exception in thread "main" java.lang.AbstractMethodError: Method A.func()Ljava/lang/Object; is abstract
	at A.func(A.java)
	at Main$.main(A1.scala:14)
	at Main.main(A1.scala)
@XYZboom XYZboom added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 17, 2025
@Gedochao Gedochao added compat:java and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 17, 2025
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

2 participants