Skip to content

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

Description

@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 #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:

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:

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)

    #if !os(macCatalyst) && !os(tvOS)
    @available(macCatalyst, unavailable)
    @available(tvOS, unavailable)
     override var tvOSUnavailableAPI: Bool {
         ...
     }
    }
    #endif

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions