Kolos65 / Mockable

A Swift macro driven auto-mocking library.
MIT License
199 stars 14 forks source link

Build Warning when Mock a `Sendable` Protocol #57

Closed vvisionnn closed 1 week ago

vvisionnn commented 2 weeks ago

Build Warning

[!WARNING]
Stored property 'mocker' of 'Sendable'-conforming class 'MockSomeSendableProtocol' is mutable

Part of Error Raised Code

import Foundation
import Mockable

@Mockable
protocol SomeSendableProtocol: Sendable {
    func randomMethod()
    func placeholder()
}
// Expanded Code
#if MOCKING
final class MockSomeSendableProtocol: SomeSendableProtocol, MockableService {
    private var mocker = Mocker<MockSomeSendableProtocol>() // <-- Error Raised Here
    @available(*, deprecated, message: "Use given(_ service:) of Mockable instead. ")
    func given() -> ReturnBuilder {
        .init(mocker: mocker)
    }
......

Minimum Repro Project

MockedSendable.zip

What Expected

Warning disappeared

hainayanda commented 1 week ago

Changing the mocker from var to let and marking the Mocker class as Sendable will remove this warning. I don't see any need to make the mocker property mutable unless for simplifies the init requirement, which can be adjusted using convenience init. But this will only move the warning to the Mocker class since many of the Mocker class members are mutable.

@Kolos65 do you mind if I look into this issue?

Kolos65 commented 1 week ago

@hainayanda I created a PR, would appreciate your review: #58

vvisionnn commented 1 week ago

Thanks @Kolos65 for the quick helping, can you please release a new version for this fix? these warnings are really annoying...