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

Fix to allow existential type to function arguments #93

Merged

Conversation

yoshiki-tsukada
Copy link
Contributor

Related #90

Hello, thank you for developing a great OSS!
I fixed a bug that occurred when function arguments contained an existential type.

The following code causes an error.

@Spyable
protocol ViewModelProtocol {
    func foo(model: any ModelProtocol)
}

class ViewModelProtocolSpy: ViewModelProtocol {
    var fooModelCallsCount = 0
    var fooModelCalled: Bool {
        return fooModelCallsCount > 0
    }
    var fooModelReceivedModel: any ModelProtocol? // ❌ Optional 'any' type must be written '(any ModelProtocol)?'
    var fooModelReceivedInvocations: [any ModelProtocol] = []
    var fooModelClosure: ((any ModelProtocol) -> Void)?
    func foo(model: any ModelProtocol) {
        fooModelCallsCount += 1
        fooModelReceivedModel = (model)
        fooModelReceivedInvocations.append((model))
        fooModelClosure?(model)
    }
}

It needs to be like this.

class ViewModelProtocolSpy: ViewModelProtocol {
    var fooModelCallsCount = 0
    var fooModelCalled: Bool {
        return fooModelCallsCount > 0
    }
    var fooModelReceivedModel: (any ModelProtocol)? // ✅
    var fooModelReceivedInvocations: [any ModelProtocol] = []
    var fooModelClosure: ((any ModelProtocol) -> Void)?
    func foo(model: any ModelProtocol) {
        fooModelCallsCount += 1
        fooModelReceivedModel = (model)
        fooModelReceivedInvocations.append((model))
        fooModelClosure?(model)
    }
}

@Matejkob Matejkob linked an issue Jun 24, 2024 that may be closed by this pull request
@Matejkob Matejkob self-assigned this Jun 24, 2024
@Matejkob Matejkob added the bug Something isn't working label Jun 24, 2024
Copy link
Owner

@Matejkob Matejkob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @yoshiki-tsukada,

thanks so much for the contribution!

The changes look good!

@Matejkob Matejkob merged commit 8c8e265 into Matejkob:main Jun 24, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

Support any
2 participants