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

Actor annotated protocols don't work #171

Open
vsanthanam opened this issue Dec 27, 2021 · 2 comments
Open

Actor annotated protocols don't work #171

vsanthanam opened this issue Dec 27, 2021 · 2 comments

Comments

@vsanthanam
Copy link
Member

If you annotate a protocol with a global actor, such as @mainactor, its generate mock doesn't compile:

Given

/// @mockable
@MainActor
protocol RootController: AnyObject {
    var viewController: UIViewController { get }
}

the mock will fail with this compilation error:



❌ /usr/local/var/buildkite-agent/builds/7003-local-1/varun-santhanam/{}/Project/{}Tests/Mocks.swift:226:16: call to main actor-isolated initializer 'init()' in a synchronous nonisolated context
--
  | return RootControllerMock()

The solution, I believe, would be to also add the actor annotation to the Mock

An identically generated mock, with the @MainActor annotation would work just fine.

I believe there would be similar errors for per-member annotations as well.

@uhooi
Copy link
Collaborator

uhooi commented Mar 28, 2022

@vsanthanam
I can generate mocks with no problem.
Would the same error occur if you use the latest version of Mockolo (1.7.0)?

@vsanthanam
Copy link
Member Author

Seems to be happening even on 1.7
note that generating the mocks isn't the problem. Its that the mocks aren't compilable.

❌ /Users/vsanthanam/Desktop/convusic-monorepo/Project/ConvusicMobileTests/Mocks.swift:498:16: call to main actor-isolated initializer 'init()' in a synchronous nonisolated context
        return MainControllerMock()

The mocks cannot invoke the initializers of their actor dependent mocks because they are not annotated correctly

Here's an attached generated but non-compiling example:
Mocks.swift.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants