uber / mockolo

Efficient Mock Generator for Swift
Apache License 2.0
804 stars 85 forks source link

Suppress Sendable protocol warnings #252

Closed Etsuwo closed 2 months ago

Etsuwo commented 5 months ago

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 commented 5 months ago

Sorry, I forgot to post my environment.

Mac OS version: Ventura 13.5.2 Xcode version : 15.0.1 Swift version : 5.9 mockolo version: 2.0.1

sidepelican commented 2 months ago

available on 2.1.1

Etsuwo commented 2 months ago

Thank you for your response! I will try the latest version.