Skip to content

[xtro-sharpie] EnumCheck drops typedef-level API_UNAVAILABLE annotations for Mac Catalyst #26166

Description

@rolfbjarne

Problem

When an Objective-C enum typedef carries API_UNAVAILABLE(maccatalyst) on the typedef (rather than on the enum body), xtro-sharpie's EnumCheck.VisitEnumDecl does not detect the unavailability and incorrectly reports the enum as !missing-enum! on Mac Catalyst.

Concrete example

In the FileProvider SDK headers (Xcode 27.0 Beta 3), the following enums are explicitly marked unavailable on Mac Catalyst:

  • NSFileProviderContentPolicy
  • NSFileProviderNamespacePolicy

When running xtro against the Mac Catalyst assembly, these are reported as:

!missing-enum! NSFileProviderContentPolicy not bound
!missing-enum! NSFileProviderNamespacePolicy not bound

These are false positives: the enums are correctly not bound for Mac Catalyst because the SDK marks them as unavailable.

Root cause

In the Clang AST, when you have:

typedef NS_ENUM(NSInteger, NSFileProviderNamespacePolicy) {
    NSFileProviderNamespacePolicyDefault = 0,
    ...
} API_UNAVAILABLE(maccatalyst);

The API_UNAVAILABLE(maccatalyst) availability attribute is attached to the TypedefDecl that names the enum, not to the EnumDecl that describes the enum body.

EnumCheck.VisitEnumDecl (tests/xtro-sharpie/xtro-sharpie/EnumCheck.cs) checks availability via:

// check availability macros to see if the API is available on the OS and not deprecated
if (!decl.IsAvailable ())
    return;

Because the availability attribute is on the TypedefDecl and not the EnumDecl, IsAvailable() returns true for Mac Catalyst, and xtro proceeds to look for the enum in the Mac Catalyst assembly—where it correctly does not exist.

Workaround

The affected entries have been added to tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-FileProvider.ignore as false positives in PR #26165.

Proposed fix

In EnumCheck.VisitEnumDecl, after checking decl.IsAvailable(), also find the corresponding TypedefDecl (if any) and check its availability. If the typedef is unavailable on the current platform, skip the enum.

Alternatively, the IsAvailable() extension on Decl (tests/xtro-sharpie/xtro-sharpie/Helpers.cs) could be extended to also walk up to any enclosing typedef and check its attributes.

Related

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions