uber / uber/mockolo

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

Open
#244 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
886
Forks
102
Avg merge
6h 36m
Merged PRs (30d)
2

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the three Swift modules and the FooBar protocol shown in the report, then trace the mock-generation path that derives handler and call-count names. The fix is done when inherited methods with the same base name receive distinct handlers and the generated FooBarMock compiles for both Int and String arguments.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
devtools, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.