mockolo
mockolo copied to clipboard
[Draft] Add protocol-level @available annotation inheritance to generated mocks
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
@availableattributes and apply them to generated mocks.
Benefits
- Prevents availability-related compilation errors.
- Aligns mock generation with Swift’s availability system.
Open to feedback!