typealiased / mockingbird

A Swifty mocking framework for Swift and Objective-C.
https://mockingbirdswift.com
MIT License
657 stars 81 forks source link

@MainActor protocol generates mock that doesn't compile #338

Open onelittlefish opened 1 month ago

onelittlefish commented 1 month ago

New Issue Checklist

Overview

If a protocol is annotated with @MainActor, the generated mock is not main actor-isolated and doesn't compile.

Example

Source:

@MainActor
protocol MyProtocol {
    func foo()
}

Generated:

public func mock(_ type: Example.MyProtocol.Protocol, file: StaticString = #file, line: UInt = #line) -> MyProtocolMock {
    return MyProtocolMock(sourceLocation: Mockingbird.SourceLocation(file, line))
}

The generated code results in a compile error:

Call to main actor-isolated initializer 'init(sourceLocation:)' in a synchronous nonisolated context

Expected Behavior

I think the generated mock() function needs to be @MainActor.

Environment

vvorlov commented 1 day ago

@onelittlefish any solution to this?