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

Mocking interface that defines public clone method fails on Scala 2.13.6 #412

Open
jrduncans opened this issue Oct 5, 2021 · 0 comments

Comments

@jrduncans
Copy link

jrduncans commented Oct 5, 2021

ScalaMock Version

5.1.0

Scala Version

2.13.6

Runtime

JVM

Please describe the expected behavior of the issue

Creation of mock successfully compiles

Please provide a description of what actually happens

[error] ....weaker access privileges in overriding
[error] def clone(): Object (defined in trait MyInterface)
[error]   override should be public;
[error]   (note that def clone(): Object (defined in trait MyInterface) is abstract,
[error]   and is therefore overridden by concrete protected[package lang] def clone(): Object (defined in class Object))
[error]       mock[MyInterface]

Reproducible Test Case

public interface MyInterface {
  public Object clone() throws CloneNotSupportedException;
}
import org.scalamock.scalatest.MockFactory
import org.scalatest.funsuite.AnyFunSuite

class Test extends AnyFunSuite with MockFactory {
  test("should be able to mock") {
    mock[MyInterface] // fails to compile on 2.13.6
  }
}

As discussed in scala/bug#12466 this behavior on Scala 2.13.6 is valid, so it seems ScalaMock needs to implement MyInterface by defining a public override of clone instead of leaving the protected abstract from Object.

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

2 participants