MakeAWishFoundation / SwiftyMocky

Framework for automatic mock generation. Adds a set of handy methods, simplifying testing. One of the best and most complete solutions, including generics support and much more.
MIT License
1.03k stars 104 forks source link

Invalid redeclaration error in .generated file while using tuples with typealias #342

Open katobi opened 1 year ago

katobi commented 1 year ago

Issue Description

We are currently using version 4.0.4 of SwiftyMocky without any issues. However, when we try to update to version 4.1.0, we encounter an issue where one of our protocol functions is generated with a duplicate function. I have identified that this issue is related to the return type of the function.

I have created an example protocol to demonstrate the issue:

typealias TupleTest = (param0: Bool, param1: Int)

// sourcery: AutoMockable
protocol BrokenProtocol {
    func test(_ parameter: Bool) -> TupleTest
    func test(_ parameter: Bool, parameter1: Int) -> TupleTest
}

extension BrokenProtocol {
    func test(_ parameter: Bool, parameter1: Int) -> TupleTest {
        return test(parameter)
    }
}

When we remove the extension, the protocol generates without any issues. Additionally, if we don't use typealiases as return values and instead use an actual tuple like this:

 func test(_ parameter: Bool) -> (param0: Bool, param1: Int)
 func test(_ parameter: Bool, parameter1: Int) -> (param0: Bool, param1: Int)

It also generates fine. We are curious to know why this behavior is occurring and if there is a way to make SwiftyMocky work as it was.

Environment

SwiftyMocky version: 4.1.0 Xcode version: 14.1

Thanks, Cagatay.