mockolo icon indicating copy to clipboard operation
mockolo copied to clipboard

Suppress Sendable protocol warnings

Open Etsuwo opened this issue 5 months ago • 1 comments

I want to create a mock from a protocol that inherits from Sendable with this OSS, but I have a problem.

Mocks generated by this OSS have variables, so if I generate a mock from a protocol that inherits from Sendable, I get a warning as shown below.

/// @mockable
protocol Hoge: Sendable {
    func hoge() -> Int
}

↓ generated

final class HogeMock: Hoge {
    init() { }

    private(set) var hogeCallCount = 0 // warning: Stored property 'hogeCallCount' of 'Sendable'-conforming class 'HogeMock' is mutable
    var hogeHandler: (() -> (Int))?
    func hoge() -> Int {
        hogeCallCount += 1
        if let hogeHandler = hogeHandler {
            return hogeHandler()
        }
        return 0
    }
}

I want to suppress unnecessary warnings because they reduce visibility and make it difficult to notice necessary warnings. For this reason, I would like to suggest that mocks generated from protocols that inherit from Sendable be marked with @unchecked sendable.

Thank you.

Etsuwo avatar Jan 18 '24 05:01 Etsuwo