[UIKit] Give priority to the UIMenuIdentifier overload of UIMenu.Create. Fixes #26267. - #26293
Conversation
The .NET 11 bindings added a new UIMenu.Create overload taking an 'NSString? identifier' alongside the existing 'UIMenuIdentifier identifier' overload. This made existing calls passing 'identifier: default' (a common pattern, since the identifier is optional) ambiguous, resulting in CS0121. Add [OverloadResolutionPriority (-1)] to the new NSString overload so the pre-existing UIMenuIdentifier-enum overload wins overload resolution, keeping 'identifier: default' unambiguous and preserving source compatibility. Fixes #26267
The System.Runtime.CompilerServices namespace wasn't imported in uikit.cs, so the [OverloadResolutionPriority] attribute added to the UIMenu.Create overload failed to compile the ApiDefinition project.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Adjusts the UIKit binding surface to preserve source compatibility after introducing a new UIMenu.Create overload that accepts an NSString identifier, by ensuring the pre-existing UIMenuIdentifier overload wins in ambiguous call sites (notably identifier: default).
Changes:
- Add
using System.Runtime.CompilerServices;to allow usingOverloadResolutionPriorityAttributein the binding definition. - Apply
[OverloadResolutionPriority (-1)]to theNSString-identifier overload so theUIMenuIdentifieroverload is preferred during overload resolution.
✅ 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.
🚀 [CI Build #30ba2a8] 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. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
Description
The .NET 11 iOS bindings added a new
UIMenu.Createoverload taking anNSString? identifieralongside the pre-existing overload taking aUIMenuIdentifier identifierenum:This is source-breaking: existing code that passes
identifier: default(a common pattern, since the identifier is optional in UIKit) now fails to compile with CS0121 (ambiguous call), becausedefaultconverts to bothUIMenuIdentifier(enum default) andNSString?(null).Fix
Add
[OverloadResolutionPriority (-1)]to the newerNSStringoverload so the pre-existingUIMenuIdentifier-enum overload wins overload resolution. This keepsidentifier: defaultunambiguous and preserves source compatibility, while still allowing callers to reach theNSStringoverload by passing an explicitNSStringargument.Also added the missing
using System.Runtime.CompilerServices;tosrc/uikit.cs, which is required for the attribute to compile in the ApiDefinition project.Testing
Verified with a clean managed build (
make all && make install) for iOS. Confirmed the generatedUIMenu.g.csnow emits the[OverloadResolutionPriority (-1)]attribute on theNSStringoverload.Fixes #26267
🤖 Pull request created by Copilot