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

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

Open
2 of 4 tasks
onelittlefish opened this issue Aug 23, 2024 · 1 comment
Open
2 of 4 tasks

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

onelittlefish opened this issue Aug 23, 2024 · 1 comment
Labels
generator bug Causes malformed generated code

Comments

@onelittlefish
Copy link

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

  • Mockingbird CLI version (0.20.0)
  • Xcode and Swift version (swift --version)
  • Package manager (SPM project)
  • Unit testing framework (XCTest)
  • Custom configuration
    • Mockingbird ignore files
    • Supporting source files
@onelittlefish onelittlefish added the generator bug Causes malformed generated code label Aug 23, 2024
@vvorlov
Copy link

vvorlov commented Sep 22, 2024

@onelittlefish any solution to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generator bug Causes malformed generated code
Projects
None yet
Development

No branches or pull requests

2 participants