Closed WedgeSparda closed 4 months ago
Thanks for the issue! Adding the return type as a generic parameter to every FunctionBuilder could potentially solve this issue. I will give it a try...
I was able to fix the issue, here's the PR https://github.com/Kolos65/Mockable/pull/14
I have looked at this and remembered why I purposefully dropped support for this edge case:
If you have a protocol with a function that uses generic parameters in both its parameter and return clause:
@Mockable
protocol Service {
func genericFunc<T, V>(item: T) -> V
}
You cannot use the perform and verify clauses when testing as the generic return parameter cannot be inferred there:
func test() {
given(mock)
.genericFunc(item: Parameter<Int>.any)
.willReturn(3)
when(mock)
.genericFunc(item: Parameter<Int>.any) // Generic parameter 'V' could not be inferred
.perform {
print("called")
}
verify(mock)
.genericFunc(item: Parameter<Int>.any) // Generic parameter 'V' could not be inferred
.called(count: .atLeastOnce)
}
This is exactly why I removed the return type from the generics of Action and Verify builders back then.
Its valid though that your use case is more common than requirements like func genericFunc<T, V>(item: T) -> V
...
Hi, I have this protocol with two methods with same name and params but different output and one of them is async
But macro is generating duplicated code at this point
Is this something that can be avoid?
Thanks