mockolo icon indicating copy to clipboard operation
mockolo copied to clipboard

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

Open Keitaro0226 opened this issue 5 months ago • 1 comments

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!

Keitaro0226 avatar Jul 10 '25 13:07 Keitaro0226

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jul 10 '25 13:07 CLAassistant