Skip to content

[xtro-sharpie] Handle typedef-level API_UNAVAILABLE on enums. Fixes #26166. - #26168

Merged
rolfbjarne merged 8 commits into
mainfrom
dev/rolf/issue-26166-xtro-sharpie-enumcheck-drops-typedef-le-3eaec2
Jul 22, 2026
Merged

rolfbjarne merged 8 commits into
mainfrom
dev/rolf/issue-26166-xtro-sharpie-enumcheck-drops-typedef-le-3eaec2

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

Clang attaches an availability attribute written after a typedef NS_ENUM(...) { ... } API_UNAVAILABLE(maccatalyst); declaration to the TypedefDecl that names the enum, not to the EnumDecl itself. This caused two problems:

  • xtro-sharpie's EnumCheck only looked at the EnumDecl's own availability, so it missed the typedef-level annotation and produced false-positive !missing-enum! reports on Mac Catalyst.
  • sharpie generated the enum binding without the corresponding availability attribute.

This fixes both:

  • EnumCheck now also checks the sibling typedef that names the enum (IsUnavailableViaTypedef) and skips the enum when that typedef is unavailable.
  • The binding generator links the naming typedef onto the EnumDecl, and the AvailabilityMassager now merges the typedef's availability attributes with the enum's own, so the generated enum carries the right [No*] attribute.

A golden-file test (tests/sharpie/Tests/EnumTypedefAvailability.*) covers the sharpie side.

Fixes #26166.

🤖 Pull request created by Copilot

rolfbjarne and others added 3 commits July 17, 2026 15:17
EnumCheck.VisitEnumDecl only checked availability on the EnumDecl itself
(decl.IsAvailable ()). When Apple marks an NS_ENUM as unavailable via a
trailing attribute on the typedef, e.g.:

    typedef NS_ENUM(NSInteger, Foo) {
        ...
    } API_UNAVAILABLE(maccatalyst);

Clang attaches the availability attribute to the TypedefDecl, not the
EnumDecl, so IsAvailable () returned true and xtro emitted false-positive
!missing-enum! entries on Mac Catalyst (seen in the FileProvider headers
in Xcode 27.0 Beta 3).

Look for the sibling typedef that names the enum and also check its
availability, skipping the enum when the typedef is unavailable on the
current platform.

Fixes #26166

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
When an Objective-C enum's availability attribute is attached to the
typedef that names the enum, e.g.:

    typedef NS_ENUM(NSInteger, Foo) {
        ...
    } API_UNAVAILABLE(maccatalyst);

Clang attaches the availability attribute to the TypedefDecl, not the
EnumDecl. The AvailabilityMassager only looked at the EnumDecl's own
attributes, so it generated the enum binding without the corresponding
availability attribute (e.g. it would omit [NoMacCatalyst]).

Link the typedef to the enum in BindingGenerator.VisitTypedefDecl (where
the enum is already being renamed from the typedef), and have the
AvailabilityMassager also consider the linked typedef's attributes when
emitting availability attributes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Adds a sharpie parse/bind golden-file test covering the native pattern from
issue #26166, where an availability attribute written after a
`typedef enum { } Name;` declaration is attached by clang to the TypedefDecl
that names the enum rather than to the EnumDecl itself. The generated C# enum
must still carry the availability attribute ([NoMac] here).

Note: this environment (Intel Mac) cannot execute sharpie's arm64-only
libclang toolchain, so the expected output could not be regenerated locally
and should be verified on CI.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a Clang AST edge case where API_UNAVAILABLE(...) written after a typedef NS_ENUM(...) { ... } ...; attaches availability to the naming TypedefDecl (not the EnumDecl), which previously caused (1) xtro false-positive !missing-enum! reports and (2) sharpie to omit the corresponding [No*] attribute on generated enums.

Changes:

  • xtro-sharpie: Skip enums in EnumCheck when the naming typedef for the enum is unavailable on the current platform.
  • sharpie: Link naming TypedefDecl → EnumDecl and merge typedef availability into enum availability during massaging.
  • Add golden-file test coverage for typedef-level availability propagation in sharpie.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tools/sharpie/Sharpie.Bind/Massagers/AvailabilityMassager.cs Merges typedef-level availability attributes into enum availability during output generation (with a noted typedef-selection issue).
tools/sharpie/Sharpie.Bind/BindingGenerator.cs Links naming TypedefDecl to the associated EnumDecl so later stages can see typedef-level availability.
tests/xtro-sharpie/xtro-sharpie/EnumCheck.cs Adds typedef-level availability check to avoid false-positive missing-enum reports.
tests/sharpie/Tests/EnumTypedefAvailability.h New sharpie regression input header demonstrating typedef-level availability on an enum.
tests/sharpie/Tests/EnumTypedefAvailability.objc.cs New sharpie golden output ensuring [No*] is emitted for typedef-level unavailability.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

- AvailabilityMassager: an enum can be linked to more than one typedef (e.g.
  typedef chains), so match the linked typedef by name to pick the one that
  actually names the generated enum instead of using FirstOrDefault, which
  could apply availability from an unrelated typedef.
- EnumCheck: cache the set of unavailable enum-naming typedefs per DeclContext
  so IsUnavailableViaTypedef is O(1) per enum instead of rescanning the whole
  DeclContext each time (avoids O(enums x siblings) work on large TUs).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

rolfbjarne and others added 4 commits July 20, 2026 15:45
The EnumCheck now detects typedef-level API_UNAVAILABLE annotations, which
surfaced a set of [Native] enums that are bound on platforms where the native
enum isn't actually available (the availability attribute is on the typedef,
not the enum). Mark each such enum [Obsolete]/[EditorBrowsable(Never)] on the
platform(s) where it's unavailable, and remove it there under XAMCORE_5_0.

Enums fixed (define = platform where obsolete):
- !MONOMAC: AVAudioRoutingArbitrationCategory
- IOS: NSFileProviderKnownFolders
- __MACCATALYST__: NSFileProviderItemCapabilities
- MONOMAC: CLServiceSessionAuthorizationRequirement
- __MACOS__: NIErrorCode, NINearbyObjectRemovalReason, NIAlgorithmConvergenceStatus,
  NINearbyObjectVerticalDirectionEstimate
- TVOS: ASAuthorizationWebBrowserPublicKeyCredentialManagerAuthorizationState,
  ASPublicKeyCredentialClientDataCrossOriginValue, ASAuthorizationPublicKeyCredentialAttachment,
  CSSuggestionKind, CSUserInteraction, UIBehavioralStyle, UIFindSessionSearchResultDisplayStyle,
  UITextSearchMatchMethod, UICornerCurve, and the five VTSuperResolutionScaler* enums

API members that reference these enums are wrapped in #pragma warning
disable/restore 618 so the api-definition build (which treats CS0618 as an
error) keeps compiling.

Also fix the EnumTypedefAvailability sharpie golden file: a shorthand [NoMac]
attribute doesn't emit `using ObjCRuntime;` (only PlatformName-based attributes
do), so the expected output shouldn't contain that using.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8775cfd7-1bef-4c1e-b693-487fe95337f2
For the natively-unavailable enums that are referenced by bound API members
(and therefore needed #pragma warning disable 618 wrappers), revert the
[Obsolete]/[EditorBrowsable(Never)] + XAMCORE_5_0 [No<platform>] treatment and
instead suppress the xtro !unknown-native-enum! error with an ignore line. This
removes the pragma noise for enums that can't cleanly be excluded without also
touching every member that references them.

NIErrorCode keeps the obsolete + XAMCORE_5_0 [NoMac] treatment because it isn't
referenced by any bound member (no pragma was needed).

Ignore lines added (per flagged platform):
- AVAudioRoutingArbitrationCategory: iOS/MacCatalyst/tvOS-AVFoundation
- NSFileProviderKnownFolders: iOS/MacCatalyst-FileProvider
- NSFileProviderItemCapabilities: MacCatalyst-FileProvider
- CLServiceSessionAuthorizationRequirement: macOS-CoreLocation
- NIAlgorithmConvergenceStatus/NINearbyObjectRemovalReason/NINearbyObjectVerticalDirectionEstimate: macOS-NearbyInteraction
- ASAuthorizationPublicKeyCredentialAttachment/ASAuthorizationWebBrowserPublicKeyCredentialManagerAuthorizationState/ASPublicKeyCredentialClientDataCrossOriginValue: tvOS-AuthenticationServices
- CSSuggestionKind/CSUserInteraction: tvOS-CoreSpotlight
- UIBehavioralStyle/UICornerCurve/UIFindSessionSearchResultDisplayStyle/UITextSearchMatchMethod: tvOS-UIKit
- the five VTSuperResolutionScaler* enums: tvOS-VideoToolbox

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8775cfd7-1bef-4c1e-b693-487fe95337f2
…xtro-sharpie-enumcheck-drops-typedef-le-3eaec2
@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne
rolfbjarne marked this pull request as ready for review July 21, 2026 17:26
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: cb951d2a3a87ffbf459387f3712efb80961ab6f8 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #cb951d2] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 203 tests passed 🎉

Tests counts

✅ assembly-processing: All 1 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 19 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 19 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 19 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. [attempt 2] Html Report (VSDrops) Download

Linux Build Verification

✅ Linux build succeeded

Pipeline on Agent
Hash: cb951d2a3a87ffbf459387f3712efb80961ab6f8 [PR build]

@rolfbjarne
rolfbjarne merged commit c733ff9 into main Jul 22, 2026
56 checks passed
@rolfbjarne
rolfbjarne deleted the dev/rolf/issue-26166-xtro-sharpie-enumcheck-drops-typedef-le-3eaec2 branch July 22, 2026 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants