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

overload inside if macro produces same variables #273

Closed
fummicc1 opened this issue Nov 10, 2024 · 1 comment · Fixed by #279
Closed

overload inside if macro produces same variables #273

fummicc1 opened this issue Nov 10, 2024 · 1 comment · Fixed by #279

Comments

@fummicc1
Copy link
Collaborator

Overload inside #if macro produces same handlers that results compile error.

  • Input
/// @mockable
protocol PresentableListener: AnyObject {
    #if DEBUG
    func run(value: Int)
    func run(value: String)
    #endif
    func run2(value: Int)
    func run2(value: String)
}
  • Output (actual)
class PresentableListenerMock: PresentableListener {
    init() { }

    #if DEBUG

    private(set) var runCallCount = 0
    var runHandler: ((Int) -> ())?
    func run(value: Int) {
        runCallCount += 1
        if let runHandler = runHandler {
            runHandler(value)
        }
        
    }

    // not supporting overload
    private(set) var runCallCount = 0
    var runHandler: ((String) -> ())?
    func run(value: String) {
        runCallCount += 1
        if let runHandler = runHandler {
            runHandler(value)
        }
        
    }
    #endif

    private(set) var run2CallCount = 0
    var run2Handler: ((Int) -> ())?
    func run2(value: Int) {
        run2CallCount += 1
        if let run2Handler = run2Handler {
            run2Handler(value)
        }
        
    }

    // supporting overload
    private(set) var run2ValueCallCount = 0
    var run2ValueHandler: ((String) -> ())?
    func run2(value: String) {
        run2ValueCallCount += 1
        if let run2ValueHandler = run2ValueHandler {
            run2ValueHandler(value)
        }
        
    }
}
  • Expected output

mock vars for second func run(value:) inside if macro should be runValueCount and runValueHandler.

@fummicc1
Copy link
Collaborator Author

fummicc1 commented Dec 7, 2024

Note: #279 fixed above case but other bug is pointed out at #279 (review)

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

Successfully merging a pull request may close this issue.

1 participant