Skip to content

[sharpie] Prefer standard protocol interfaces over [Model] classes in type mapping#24913

Merged
rolfbjarne merged 2 commits intomainfrom
dev/rolf/sharpie-protocols-fix
Mar 18, 2026
Merged

[sharpie] Prefer standard protocol interfaces over [Model] classes in type mapping#24913
rolfbjarne merged 2 commits intomainfrom
dev/rolf/sharpie-protocols-fix

Conversation

@rolfbjarne
Copy link
Member

When two types in the platform assembly map to the same native name,
prefer the standard protocol interface (named "I" + nativeName, e.g.
INSCopying for native "NSCopying") over a [Model] class stub.

Previously, collisions between a [Model] class (e.g. NSCopying with
[Protocol()]) and the protocol interface (INSCopying with
[Protocol(Name="NSCopying")]) would cause both mappings to be
dropped entirely. Now the standard protocol interface wins, so types
like NSCopying in generic constraints are correctly mapped to
INSCopying.

… type mapping

When two types in the platform assembly map to the same native name,
prefer the standard protocol interface (named "I" + nativeName, e.g.
INSCopying for native "NSCopying") over a [Model] class stub.

Previously, collisions between a [Model] class (e.g. NSCopying with
[Protocol()]) and the protocol interface (INSCopying with
[Protocol(Name="NSCopying")]) would cause both mappings to be
dropped entirely. Now the standard protocol interface wins, so types
like NSCopying in generic constraints are correctly mapped to
INSCopying.

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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates Sharpie’s platform type mapping collision handling so that when multiple managed types map to the same native protocol name, the conventional protocol interface (I + nativeName) is preferred over [Model] protocol stubs—fixing incorrect mappings in generated generic constraints.

Changes:

  • Adjusted platform assembly type-map collision resolution to prefer standard protocol interfaces and only drop mappings on true ambiguity.
  • Added tracking for “standard protocol interface” entries during map construction.
  • Updated Sharpie generics expected outputs to use INSCopying instead of NSCopying in NSObject<..., ...> protocol-constrained generics.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tools/sharpie/Sharpie.Bind/Massagers/PlatformTypeMappingMassager.cs Refines native-name collision resolution to keep standard protocol interfaces and avoid dropping both mappings unnecessarily.
tests/sharpie/Tests/ObjCGenerics.macosx.cs Updates expected generated generics to use INSCopying in protocol generic constraints.
tests/sharpie/Tests/ObjCGenerics.iphoneos.cs Updates expected generated generics to use INSCopying in protocol generic constraints.

You can also share your feedback on Copilot code review. Take the survey.

Co-authored-by: Copilot Autofix powered by AI <175728472+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.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #3d8c14f] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 3d8c14f922434c332b36573f14a40a1952a4d526 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [PR Build #3d8c14f] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 3d8c14f922434c332b36573f14a40a1952a4d526 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
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: 3d8c14f922434c332b36573f14a40a1952a4d526 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #3d8c14f] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 3d8c14f922434c332b36573f14a40a1952a4d526 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🚀 [CI Build #3d8c14f] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 156 tests passed 🎉

Tests counts

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. 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 6 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 12 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 11 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. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 3d8c14f922434c332b36573f14a40a1952a4d526 [PR build]

@rolfbjarne rolfbjarne enabled auto-merge (squash) March 18, 2026 08:21
@rolfbjarne rolfbjarne merged commit b427ce7 into main Mar 18, 2026
48 checks passed
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.

4 participants