Skip to content

error overriding method with different access levels in inheritors #19007

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

Closed
unkarjedy opened this issue Nov 20, 2023 · 2 comments · Fixed by #18953
Closed

error overriding method with different access levels in inheritors #19007

unkarjedy opened this issue Nov 20, 2023 · 2 comments · Fixed by #18953

Comments

@unkarjedy
Copy link
Contributor

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).

@unkarjedy unkarjedy added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 20, 2023
@unkarjedy
Copy link
Contributor Author

For now, the workaround is to explicitly override the clone method:

class MyRunConfigurationScala extends RunConfigurationBase {
  override def clone(): RunConfiguration = super.clone()
}

@EugeneFlesselle
Copy link
Contributor

I believe this is a duplicate of #18654 and is also fixed by the associated PR #18953

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

Successfully merging a pull request may close this issue.

2 participants