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 "ACC_BRIDGE, ACC_SYNTHETIC" in bytecode cause java could not compile #13075

Open
XYZboom opened this issue Jan 5, 2025 · 10 comments
Open

Comments

@XYZboom
Copy link

XYZboom commented Jan 5, 2025

Reproduction steps

Scala version: 2.13.15

// Java files
// FILE: I0.java
public interface I0<T0> {
    public abstract void func(T0 arg);
}
// FILE: I1.java
public interface I1<T> extends I0<T> {
    public default void func(T arg) {
    }
}
open class A0 extends I1[String] {
}
// Java Files
// FILE: A1.java
public final class A1 extends A0 implements I0<String> {
    public void func(String arg) {
    }
}

Problem

Java compiler reports error but no error in scala3:

A1.java:2: error: name clash: func(String) in A1 overrides a method whose erasure is the same as another method, yet neither overrides the other
    public void func(String arg) {
                ^
  first method:  func(Object) in A0
  second method: func(T) in I1
  where T is a type-variable:
    T extends Object declared in interface I1
1 error

use javap -c -s -v to view A0.class:

func of A0 compiled by scala2 in javap output

public void func(java.lang.Object);
    descriptor: (Ljava/lang/Object;)V
    flags: ACC_PUBLIC

func of A0 compiled by scala3 in javap output

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

We can see that A0.func compiled by scala2 misses "ACC_BRIDGE, ACC_SYNTHETIC"

@lrytz
Copy link
Member

lrytz commented Jan 6, 2025

As far as I can tell, your report only has .java source files. The Scala compiler does not produce any bytecode / .class files from Java sources.

Please clarify step by step how to reproduce the issue. Feel free to re-open.

@lrytz lrytz closed this as not planned Won't fix, can't repro, duplicate, stale Jan 6, 2025
@XYZboom
Copy link
Author

XYZboom commented Jan 6, 2025

As far as I can tell, your report only has .java source files. The Scala compiler does not produce any bytecode / .class files from Java sources.

Please clarify step by step how to reproduce the issue. Feel free to re-open.

Perhaps you missed the A0 class, which is a Scala class. The other three files I0, I1 and A1 are Java.
Firstly, you need to compile I0 and I1 use javac. Then compile A0 use scalac. Finally you will find A1 could not be compiled.
But if A0 is writen in Java or is compiled by scala3, A1 can be compiled. So I think it's a compiler bug in scala2.

@XYZboom
Copy link
Author

XYZboom commented Jan 6, 2025

@lrytz It seems like I don't have permission to reopen an issue.

@lrytz lrytz reopened this Jan 6, 2025
@som-snytt
Copy link

I made the same mistake when I looked at the other ticket. We need a better way to specify the reproduction. I'm not sure scala-cli directives suffice.

@XYZboom
Copy link
Author

XYZboom commented Jan 6, 2025

I made the same mistake when I looked at the other ticket. We need a better way to specify the reproduction. I'm not sure scala-cli directives suffice.

@som-snytt If you are using IntelliJ Idea, reproduction will be easier. If you are referring to adding a test case in the compiler to reproduce, perhaps you can refer to Kotlin's test suite, which can simply put Kotlin and Java in the same file and use the test suite to reproduce the problem. I can give you some examples from Kotlin, such as this one. Kotlin's testing suite can parse comments in a single test file and read some configurations from it.

@SethTisue
Copy link
Member

Does Scala 3 handle it correctly?

@XYZboom
Copy link
Author

XYZboom commented Jan 7, 2025

Does Scala 3 handle it correctly?

Yes, Scala 3 handle it correctly. You can see that compared to Scala 3, Scala 2 misses "ACC_BRIDGE, ACC_SYNTHETIC" in bytecode

@XYZboom
Copy link
Author

XYZboom commented Jan 7, 2025

@SethTisue A possible off topic question, if Scala2 and Scala3 have the same bug, do I need to report it again here?

@sjrd
Copy link
Member

sjrd commented Jan 7, 2025

Scala 3 has the flags but needs to get rid of them:
scala/scala3#19270

@SethTisue
Copy link
Member

SethTisue commented Jan 7, 2025

A possible off topic question, if Scala2 and Scala3 have the same bug, do I need to report it again here?

A good place to ask questions like this is https://contributors.scala-lang.org

If the bug is in the Scala 2 standard library (which Scala 3 incorporates as-is), you should report it to the Scala 2 tracker only, as that's where the bug will need to be fixed.

For compiler bugs like this one... I can't really give unequivocal guidance. It's certainly considered legit to report it to both repos, if you crosslink the two tickets. But, I wouldn't automatically do it every time. I would normally suggest picking one repo or the other to start in, to confirm that the bug is actually a bug and to gauge the level of interest from maintainers and other users.

Which repo to report to first? I don't know, my impression is that users generally just report it against whatever version they were using, since that's probably the version they care most about. Even if we tried to make rules about this, that's how users would go on behaving regardless :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants