[sharpie] Prefer standard protocol interfaces over [Model] classes in type mapping#24913
[sharpie] Prefer standard protocol interfaces over [Model] classes in type mapping#24913rolfbjarne merged 2 commits intomainfrom
Conversation
… 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>
There was a problem hiding this comment.
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
INSCopyinginstead ofNSCopyinginNSObject<..., ...>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.
tools/sharpie/Sharpie.Bind/Massagers/PlatformTypeMappingMassager.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+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.
✅ [CI Build #3d8c14f] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #3d8c14f] Build passed (Detect API changes) ✅Pipeline on Agent |
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 |
✅ [CI Build #3d8c14f] Build passed (Build macOS tests) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
🚀 [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 macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
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.