Skip to content

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

Open
Keitaro0226 wants to merge 4 commits intouber:masterfrom
Keitaro0226:fix-available-annotation-handling
Open

Add protocol-level @available annotation inheritance to generated mocks#315
Keitaro0226 wants to merge 4 commits intouber:masterfrom
Keitaro0226:fix-available-annotation-handling

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.

@sidepelican
Copy link
Collaborator

Any updates on this? When this draft PR becomes ready?

@Keitaro0226
Copy link
Author

Sorry for the long silence. I got sidetracked and lost track of this.

I'll add tests and mark this PR as ready soon. Thanks for your patience.

@Keitaro0226 Keitaro0226 changed the title [Draft] Add protocol-level @available annotation inheritance to generated mocks Add protocol-level @available annotation inheritance to generated mocks Mar 26, 2026
@Keitaro0226 Keitaro0226 marked this pull request as ready for review March 26, 2026 15:39
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

3 participants