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

Generated Automockable compilation issue due to malformed generated variable name #1264

Closed
pocketal opened this issue Jan 23, 2024 · 2 comments

Comments

@pocketal
Copy link
Contributor

The generated Automockable does not compile in case of a procotol contains reference to a composite type

Exemple:

For a given protocol:

protocol FooProtocol {}

protocol BarProtocol {}

// sourcery: AutoMockable
protocol AProtocol {
    func execute(parameter: any (FooProtocol & BarProtocol))
}

The generated mock should look like this:

class AProtocolMock: AProtocol {
    //MARK: - execute

    var executeParameterAnyFooProtocolBarProtocolVoidCallsCount = 0
    var executeParameterAnyFooProtocolBarProtocolVoidCalled: Bool {
        return executeParameterAnyFooProtocolBarProtocolVoidCallsCount > 0
    }
    var executeParameterAnyFooProtocolBarProtocolVoidReceivedParameter: (any (FooProtocol & BarProtocol))?
    var executeParameterAnyFooProtocolBarProtocolVoidReceivedInvocations: [(any (FooProtocol & BarProtocol))] = []
    var executeParameterAnyFooProtocolBarProtocolVoidClosure: ((any (FooProtocol & BarProtocol)) -> Void)?

    func execute(parameter: any (FooProtocol & BarProtocol)) {
        executeParameterAnyFooProtocolBarProtocolVoidCallsCount += 1
        executeParameterAnyFooProtocolBarProtocolVoidReceivedParameter = parameter
        executeParameterAnyFooProtocolBarProtocolVoidReceivedInvocations.append(parameter)
        executeParameterAnyFooProtocolBarProtocolVoidClosure?(parameter)
    }
}

However it looks like this: (notice the presence of & in the variables names)

class AProtocolMock: AProtocol {

    //MARK: - execute

    var executeParameterAnyFooProtocol&BarProtocolVoidCallsCount = 0
    var executeParameterAnyFooProtocol&BarProtocolVoidCalled: Bool {
        return executeParameterAnyFooProtocol&BarProtocolVoidCallsCount > 0
    }
    var executeParameterAnyFooProtocol&BarProtocolVoidReceivedParameter: (any (FooProtocol & BarProtocol))?
    var executeParameterAnyFooProtocol&BarProtocolVoidReceivedInvocations: [(any (FooProtocol & BarProtocol))] = []
    var executeParameterAnyFooProtocol&BarProtocolVoidClosure: ((any (FooProtocol & BarProtocol)) -> Void)?

    func execute(parameter: any (FooProtocol & BarProtocol)) {
        executeParameterAnyFooProtocol&BarProtocolVoidCallsCount += 1
        executeParameterAnyFooProtocol&BarProtocolVoidReceivedParameter = parameter
        executeParameterAnyFooProtocol&BarProtocolVoidReceivedInvocations.append(parameter)
        executeParameterAnyFooProtocol&BarProtocolVoidClosure?(parameter)
    }
}
@pocketal
Copy link
Contributor Author

This PR should fix this issue

@krzysztofzablocki
Copy link
Owner

thanks for contributing!

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

2 participants