ScalaMock
ScalaMock copied to clipboard
Cannot mock overloaded methods if types of their arguments are parametrised with wildcard type
There is a compilation error when I try to mock a class with overloaded methods that have arguments of a generic type parametrised with a wildcard type.
Example:
class P[T]
class A[F[_]]
class B[F[_]]
trait Fooer[F[_]] {
def foo(x: A[F]): Unit
def foo(x: B[F]): Unit
}
val mockFooer: Fooer[P] = mock[Fooer[P]]
(mockFooer.foo(_: A[P])).expects(new A[P])
(mockFooer.foo(_: B[P])).expects(new B[P])
Errors:
value expects is not a member of this.A[this.P] => Unit
(mockFooer.foo(_: A[P])).expects(new A[P])
value expects is not a member of this.B[this.P] => Unit
(mockFooer.foo(_: B[P])).expects(new B[P])
However, I expect successful compilation.
Versions:
sbt 1.5.5
jdk AdoptOpenJDK Java 11.0.11
scala 2.13.6
scalamock 5.1.0