Skip to content

error overriding method with different access levels in inheritors #19007

Closed
@unkarjedy

Description

@unkarjedy

Compiler version

3.3.1

Minimized code

3 Java files

public interface RunConfiguration extends Cloneable {
  RunConfiguration clone();
}
public abstract class RunConfigurationBase<T> extends UserDataHolderBase implements RunConfiguration {
    @Override
    public RunConfiguration clone() {
        return null;
    }
}
import java.util.concurrent.atomic.AtomicReference;

public class UserDataHolderBase extends AtomicReference<String> {
    @Override
    protected Object clone() {
        return null;
    }
}

Main Scala File

class MyRunConfigurationScala extends RunConfigurationBase

Output

Compile the code.
Observe compilation error:

.../src/main/scala/MyRunConfigurationScala.scala
error overriding method clone in trait RunConfiguration of type (): RunConfiguration;
  method clone² in class UserDataHolderBase of type (): Object has weaker access privileges; it should be public

where:    clone  is a method in trait RunConfiguration
          clone² is a method in class UserDataHolderBase

class MyRunConfigurationScala extends RunConfigurationBase

Expectation

The code compiles fine.
Note that it compiles with Scala 2 compiler.
Also Java compiler compiles fine a similar code:
MyRunConfigurationJava.java

public class MyRunConfigurationJava extends RunConfigurationBase {
}

Note that this is a minimised example from the Scala Plugin project.
I tried to extract another module to Scala 3 and got this error.
Java classes are from library (IntelliJ SDK).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions