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

[Bug] Protocol that inherits from protocols in two different modules with same function name does not produce unique handlers #244

Open
ryanaveo opened this issue Jun 26, 2023 · 2 comments

Comments

@ryanaveo
Copy link
Contributor

ryanaveo commented Jun 26, 2023

Environment

macOS 13.4.1
Swift version 5.8.1
Xcode 14.3.1
v2.0.1

Issue

The following code produces a mock that does not compile successfully

Protocols to Mock

// ModuleA

/// @CreateMock
public protocol Foo {
    func foo(num: Int)
}
// ModuleB

/// @CreateMock
public protocol Bar {
    func foo(text: String)
}
// Module C
import ModuleA
import ModuleB

/// @CreateMock
public protocol FooBar: Foo, Bar {}

Generated Mock

public class FooBarMock: FooBar {
    public init() { }

    public var fooCallCount = 0
    public var fooHandler: ((Int) -> ())?
    public func foo(num: Int)  {
        mockFunc(&fooCallCount)("foo", fooHandler?(num), .void)
    }
    public func foo(text: String)  {
        mockFunc(&fooCallCount)("foo", fooHandler?(text), .void) // error found here because fooHandler expects an Int, not a string
    }
}

Error

error: cannot convert value of type 'String' to expected argument type 'Int'
        mockFunc(&fooCallCount)("foo", fooHandler?(text), .void)
@toddlee
Copy link

toddlee commented Feb 16, 2024

any update on this? simplest solution would be to add some increasing index to ones after the first one with the same name.

@Ricardo1980
Copy link

I have exactly the same issue.
A potential solution could be adding a prefix or suffix to the generated mock using something like:
/// @mockable(method: postfix = Foo)

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

3 participants