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] Doesn't support multiple functions of the same name with different parameters #19

Open
brzzdev opened this issue Jul 4, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@brzzdev
Copy link

brzzdev commented Jul 4, 2023

@Spyable
internal protocol MyHapticsProtocol {
    func send(_ style: UIImpactFeedbackGenerator.FeedbackStyle)
    func send(_ type: UINotificationFeedbackGenerator.FeedbackType)
}

results in a bunch Invalid redeclaration of ... warnings

@Matejkob Matejkob added the bug Something isn't working label Nov 9, 2023
@dafurman
Copy link
Contributor

@brzzdev In your example, while possibly not ideal, this could be worked around by externalizing the argument labels:

internal protocol MyHapticsProtocol {
    func send(style: UIImpactFeedbackGenerator.FeedbackStyle)
    func send(type: UINotificationFeedbackGenerator.FeedbackType)
}

This will result in generated code using the parameter names in property names, which will allow the two to be distinguished.

That said, this issue does shed light on an edge case where the function and parameter names are the exact same, but take different types.
I could see this being a problem in code that may have APIs that look a bit more generic, like this:

protocol InputSender {
    func send(input: KeyboardInput)
    func send(input: MouseInput)
}

The only thing that'd we'd have to differentiate the functions would be the parameters' actual type. If we detect that two functions have the same signatures, I think our only option might generating code that includes the type names:

class InputSenderSpy: InputSender {
    var sendInputKeyboardInputCallsCount = 0
    var sendInputKeyboardInputCalled: Bool {
        return sendInputKeyboardInputCallsCount > 0
    }
    var sendInputKeyboardInputReceivedInput: KeyboardInput?
    var sendInputKeyboardInputReceivedInvocations: [KeyboardInput] = []
    var sendInputKeyboardInputClosure: ((KeyboardInput) -> Void)?
    func send(input: KeyboardInput) {
        sendInputKeyboardInputCallsCount += 1
        sendInputKeyboardInputReceivedInput = (input)
        sendInputKeyboardInputReceivedInvocations.append((input))
        sendInputKeyboardInputClosure?(input)
    }
    var sendInputMouseInputCallsCount = 0
    var sendInputMouseInputCalled: Bool {
        return sendInputMouseInputCallsCount > 0
    }
    var sendInputMouseInputReceivedInput: MouseInput?
    var sendInputMouseInputReceivedInvocations: [MouseInput] = []
    var sendInputMouseInputClosure: ((MouseInput) -> Void)?
    func send(input: MouseInput) {
        sendInputMouseInputCallsCount += 1
        sendInputMouseInputReceivedInput = (input)
        sendInputMouseInputReceivedInvocations.append((input))
        sendInputMouseInputClosure?(input)
    }
}

A more visually-pleasing option may be throwing in some underscores into these properties, like
send_UINotificationFeedbackGeneratorFeedbackType_CallsCount.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants