Skip to content

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

Description

@ryanaveo

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions