scala3mock
scala3mock copied to clipboard
Issue with methods of multiple param lists where one is vargs
Hello again @fmonniot, I've bumped into another issue trying to mock such service:
trait Service {
def method(a: Int*)(b: String): Unit
}
compile output with debug:
Mocking type Service
Generated code:
Tree Code: {
class ServiceMock extends java.lang.Object with Service with eu.monniot.scala3mock.context.Mock {
private val mocks: scala.collection.immutable.Map[scala.Predef.String, eu.monniot.scala3mock.functions.MockFunction] = scala.Predef.Map.from[java.lang.String, eu.monniot.scala3mock.functions.MockFunction](new scala.Tuple2[java.lang.String, eu.monniot.scala3mock.functions.MockFunction]("method", new eu.monniot.scala3mock.functions.MockFunction2[_*, scala.Predef.String, scala.Unit](TypeCheckTest.currentContext, "<TypeCheckTest.scala#L10> Service.method")(eu.monniot.scala3mock.Default.given_Default_Unit)))
def accessMockFunction(name: java.lang.String): eu.monniot.scala3mock.functions.MockFunction = ServiceMock.this.mocks.apply(name)
override def method(a: _*)(b: scala.Predef.String): scala.Unit = ServiceMock.this.mocks.apply("method").asInstanceOf[eu.monniot.scala3mock.functions.MockFunction2[_*, scala.Predef.String, scala.Unit]].apply(a, b)
}
(new ServiceMock(): Service & eu.monniot.scala3mock.context.Mock)
}
[error] -- [E007] Type Mismatch Error: /Users/nikitaglushchenko/Desktop/projects/untitled/src/main/scala/TypeCheckTest.scala:11:56
[error] 11 | private val service = mockWithDebuggingOutput[Service]
[error] | ^
[error] | Found: (a : Int*)
[error] | Required: Int
[error] |----------------------------------------------------------------------------
[error] |Inline stack trace
[error] |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error] |This location contains code that was inlined from TypeCheckTest.scala:11
[error] ----------------------------------------------------------------------------
[error] |
[error] | longer explanation available when compiling with `-explain`
[error] one error found
What might be potentially interesting for investigation is that such service:
trait Service {
def method(a: Int*): Unit
}
compiles fine:
Tree Code: {
class ServiceMock extends java.lang.Object with Service with eu.monniot.scala3mock.context.Mock {
private val mocks: scala.collection.immutable.Map[scala.Predef.String, eu.monniot.scala3mock.functions.MockFunction] = scala.Predef.Map.from[java.lang.String, eu.monniot.scala3mock.functions.MockFunction](new scala.Tuple2[java.lang.String, eu.monniot.scala3mock.functions.MockFunction]("method", new eu.monniot.scala3mock.functions.MockFunction1[_*, scala.Unit](TypeCheckTest.currentContext, "<TypeCheckTest.scala#L10> Service.method")(eu.monniot.scala3mock.Default.given_Default_Unit)))
def accessMockFunction(name: java.lang.String): eu.monniot.scala3mock.functions.MockFunction = ServiceMock.this.mocks.apply(name)
override def method(a: _*): scala.Unit = ServiceMock.this.mocks.apply("method").asInstanceOf[eu.monniot.scala3mock.functions.MockFunction1[_*, scala.Unit]].apply(a)
}
(new ServiceMock(): Service & eu.monniot.scala3mock.context.Mock)
}