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

Open
fummicc1 opened this issue Nov 10, 2024 · 0 comments
Open

overload inside if macro produces same variables #273

fummicc1 opened this issue Nov 10, 2024 · 0 comments

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.

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

1 participant