Repository navigation
[xtro-sharpie] Handle typedef-level API_UNAVAILABLE on enums. Fixes #26166. - #26168
rolfbjarne merged 8 commits into
Conversation
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>
There was a problem hiding this comment.
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
EnumCheckwhen the naming typedef for the enum is unavailable on the current platform. - sharpie: Link naming
TypedefDecl→EnumDecland 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. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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
This comment has been minimized.
This comment has been minimized.
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
🚀 [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 macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. [attempt 2] Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
Clang attaches an availability attribute written after a
typedef NS_ENUM(...) { ... } API_UNAVAILABLE(maccatalyst);declaration to theTypedefDeclthat names the enum, not to theEnumDeclitself. This caused two problems:EnumCheckonly looked at theEnumDecl's own availability, so it missed the typedef-level annotation and produced false-positive!missing-enum!reports on Mac Catalyst.This fixes both:
EnumChecknow also checks the sibling typedef that names the enum (IsUnavailableViaTypedef) and skips the enum when that typedef is unavailable.EnumDecl, and theAvailabilityMassagernow 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