Skip to content

Missing "ACC_BRIDGE, ACC_SYNTHETIC" in bytecode cause java could not compile #13075

@XYZboom

Description

@XYZboom

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions