Add protocol-level @available annotation inheritance to generated mocks#315
Add protocol-level @available annotation inheritance to generated mocks#315Keitaro0226 wants to merge 4 commits intouber:masterfrom
Conversation
|
Any updates on this? When this draft PR becomes ready? |
|
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. |
sidepelican
left a comment
There was a problem hiding this comment.
Thanks for the PR. Overall it looks good, but I noticed a few minor details that I'd like you to address before we merge.
| /// @mockable | ||
| @available(iOS 18.0, *) | ||
| public protocol Foo: Sendable { | ||
| func bar() -> String | ||
| } |
There was a problem hiding this comment.
I want to enforce a compilation error when @available isn't applied to a mock.
| /// @mockable | |
| @available(iOS 18.0, *) | |
| public protocol Foo: Sendable { | |
| func bar() -> String | |
| } | |
| @available(macOS 99.0, *) | |
| struct Bar {} | |
| /// @mockable | |
| @available(macOS 99.0, *) | |
| protocol Foo: Sendable { | |
| func bar() -> Bar | |
| } |
|
|
||
| func model() -> Model { | ||
| let metadata = entity.metadata | ||
| // Combine protocol-level attributes with member-level attributes |
There was a problem hiding this comment.
| // Combine protocol-level attributes with member-level attributes |
The meaning feels a bit off and it’s redundant, so let's remove it.
| } | ||
|
|
||
| @MainActor | ||
| /// @mockable |
There was a problem hiding this comment.
It's strange for @mockable to come along too.
How about just inheriting available?
You can change EntityNode.attributesDescription requirement to var attributes: [String] { get }.
| return "" | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
I need a test case for protocol inheritance scenarios:
@available(macOS 100.0, *)
struct Bar {}
@available(macOS 90.0, *)
protocol Foo {
}
/// @mockable
@available(macOS 100.0, *)
protocol Foo2: Foo {
var bar: Bar { get set }
}
Overview
Fixes #314
This draft PR addresses an issue where
@availableannotations 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
@availableannotations, 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
Incorrect mock (missing
@available):Correct mock:
Solution
@availableattributes and apply them to generated mocks.Benefits
Open to feedback!