Skip to content

[Draft] Add protocol-level @available annotation inheritance to generated mocks #315

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Keitaro0226
Copy link

Overview

Fixes #314

This draft PR addresses an issue where @available annotations on protocols are not inherited by the generated mock classes. This can cause compilation errors when the protocol uses types or members that are only available in specific OS versions.

Problem

Currently, when generating mocks for protocols with @available annotations, Mockolo does not apply these availability constraints to the generated mock. As a result, using the mock can trigger compile-time errors when availability-constrained types or members are involved.

Example

/// @mockable
@available(iOS 18.0, *)
protocol Foo: Sendable {
    func bar()
}

Incorrect mock (missing @available):

public final class FooMock: Foo, @unchecked Sendable { 
    // ❌ Missing @available
}

Correct mock:

@available(iOS 18.0, *)
public final class FooMock: Foo, @unchecked Sendable { 
}

Solution

  • Extract protocol-level @available attributes and apply them to generated mocks.

Benefits

  • Prevents availability-related compilation errors.
  • Aligns mock generation with Swift’s availability system.

Open to feedback!

@CLAassistant
Copy link

CLAassistant commented Jul 10, 2025

CLA assistant check
All committers have signed the CLA.

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

Successfully merging this pull request may close these issues.

Generated mocks do not inherit protocol-level @available annotations
2 participants