Regression: `@available(..., unavailable)` declarations generate unsupported mocks in Cuckoo 2.x

#599 ยท open ยท 0 comments

View on GitHub โ†—

stonko1994

**Description** We are currently attempting to update to Cuckoo 2.x but found a regression/blocker that prevents us from doing so. We initially contributed a solution for `@available` in https://github.com/Brightify/Cuckoo/pull/423. However, during migration to 2.x we observed that the original issue is back. Original description (from the linked PR): --- # Problem In case of a cross-platform codebase where some APIs are marked with e.g. `@available(tvOS, unavailable)` the Cuckoo generated code can not be compiled due to error `Cannot override 'tvOSUnavailableAPI' which has been marked unavailable` when building for the "forbidden" platform. Like with this type to mock: ```swift class TestClass { @available(tvOS, unavailable) var tvOSUnavailableAPI: Bool = true } ``` I am happy to take any feedback. I didn't know how to add unit tests for this project (seems a bit unconventional ๐Ÿ˜…), but happy to do so if I get some instructions how the setup works. # Proposed solution I have built a POC where I extracted the platform value (`"tvOS"` from the above example) and wrapped the affected API with `#if !os(unavailablePlatform)`. In case of multiple unavailable platforms: ```swift class TestClass { @available(tvOS, unavailable) @available(macCatalyst, unavailable) var tvOSUnavailableAPI: Bool = true var generallyAvailableApi: String = "hello" } ``` it would result like this: `#if !os(tvOS) && !os(macCatalyst)` (see below) ```swift #if !os(macCatalyst) && !os(tvOS) @available(macCatalyst, unavailable) @available(tvOS, unavailable) override var tvOSUnavailableAPI: Bool { ... } } #endif ```

Comments