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

Templates/AutoMockable.stencil: fix stencil to consider nullable closures as escaping #1358

Merged

Conversation

alexdmotoc
Copy link
Contributor

Refines work done in #1126 by allowing generating invocation vars for methods with nullable closures, as those are implicitly escaping, for which it's safe to generate such vars

e.g.

Before

class NullableClosureProtocolMock: NullableClosureProtocol {
    var setClosureClosureVoidVoidCallsCount = 0
    var setClosureClosureVoidVoidCalled: Bool {
        return setClosureClosureVoidVoidCallsCount > 0
    }
    var setClosureClosureVoidVoidClosure: (((() -> Void)?) -> Void)?

    func setClosure(_ closure: (() -> Void)?) {
        setClosureClosureVoidVoidCallsCount += 1
        setClosureClosureVoidVoidClosure?(closure)
    }
}

After

class NullableClosureProtocolMock: NullableClosureProtocol {
    var setClosureClosureVoidVoidCallsCount = 0
    var setClosureClosureVoidVoidCalled: Bool {
        return setClosureClosureVoidVoidCallsCount > 0
    }
    var setClosureClosureVoidVoidReceivedClosure: (((() -> Void)))? // this was missing
    var setClosureClosureVoidVoidReceivedInvocations: [(((() -> Void)))?] = [] // this was missing
    var setClosureClosureVoidVoidClosure: (((() -> Void)?) -> Void)?

    func setClosure(_ closure: (() -> Void)?) {
        setClosureClosureVoidVoidCallsCount += 1
        setClosureClosureVoidVoidReceivedClosure = closure
        setClosureClosureVoidVoidReceivedInvocations.append(closure)
        setClosureClosureVoidVoidClosure?(closure)
    }
}

@krzysztofzablocki krzysztofzablocki merged commit 8acc3bf into krzysztofzablocki:master Sep 10, 2024
1 of 2 checks passed
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 this pull request may close these issues.

3 participants