Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/sharpie/Tests/ObjCGenerics.iphoneos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
interface CNLabeledValue : INSCopying, INSSecureCoding {
// @property (readonly, copy, nonatomic) ValueType ValueTypeProperty;
[Export ("ValueTypeProperty", ArgumentSemantic.Copy)]
NSObject<NSCopying, INSSecureCoding> ValueTypeProperty { get; }
NSObject<INSCopying, INSSecureCoding> ValueTypeProperty { get; }

// -(ValueType _Nullable)getValueTypeMethod;
[NullAllowed, Export ("getValueTypeMethod")]
[Verify (MethodToProperty)]
NSObject<NSCopying, INSSecureCoding> ValueTypeMethod { get; }
NSObject<INSCopying, INSSecureCoding> ValueTypeMethod { get; }

// -(void)setValueTypeMethod:(ValueType _Nullable)obj;
[Export ("setValueTypeMethod:")]
void SetValueTypeMethod ([NullAllowed] NSObject<NSCopying, INSSecureCoding> obj);
void SetValueTypeMethod ([NullAllowed] NSObject<INSCopying, INSSecureCoding> obj);
}

// @protocol A
Expand Down
6 changes: 3 additions & 3 deletions tests/sharpie/Tests/ObjCGenerics.macosx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
interface CNLabeledValue : INSCopying, INSSecureCoding {
// @property (readonly, copy, nonatomic) ValueType ValueTypeProperty;
[Export ("ValueTypeProperty", ArgumentSemantic.Copy)]
NSObject<NSCopying, INSSecureCoding> ValueTypeProperty { get; }
NSObject<INSCopying, INSSecureCoding> ValueTypeProperty { get; }

// -(ValueType _Nullable)getValueTypeMethod;
[NullAllowed, Export ("getValueTypeMethod")]
[Verify (MethodToProperty)]
NSObject<NSCopying, INSSecureCoding> ValueTypeMethod { get; }
NSObject<INSCopying, INSSecureCoding> ValueTypeMethod { get; }

// -(void)setValueTypeMethod:(ValueType _Nullable)obj;
[Export ("setValueTypeMethod:")]
void SetValueTypeMethod ([NullAllowed] NSObject<NSCopying, INSSecureCoding> obj);
void SetValueTypeMethod ([NullAllowed] NSObject<INSCopying, INSSecureCoding> obj);
}

// @protocol A
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Sharpie.Bind.Massagers;
[RegisterBefore (typeof (GenerateUsingStatementsMassager))]
public sealed class PlatformTypeMappingMassager : Massager<PlatformTypeMappingMassager> {
readonly Dictionary<string, (string FullName, string Namespace, string Name)> typeMap = new ();
readonly Dictionary<string, (string FullName, string Namespace, string Name)> protocolMap = new ();
readonly HashSet<string> protocolEntries = new ();
readonly Stack<bool> ignoreType = new Stack<bool> ();

public PlatformTypeMappingMassager (ObjectiveCBinder binder)
Expand All @@ -23,6 +23,7 @@ public PlatformTypeMappingMassager (ObjectiveCBinder binder)
public override bool Initialize ()
{
typeMap.Clear ();
protocolEntries.Clear ();

var path = base.Binder.PlatformAssembly;
var decoder = new TypelessDecoder ();
Expand Down Expand Up @@ -73,12 +74,30 @@ public override bool Initialize ()
var etName = mr.GetString (et.Name);
nativeName ??= etName;

var map = typeMap;
if (map.Remove (nativeName)) {
// there would be a collision, so skip adding again
continue;
var entry = (etNamespace + "." + etName, etNamespace, etName);
if (typeMap.ContainsKey (nativeName)) {
// When two types map to the same native name, prefer the
// standard protocol interface (named "I" + nativeName, e.g.
// INSCopying for "NSCopying") over a [Model] class or a
// non-standard protocol. If neither or both follow the
// convention, drop both (genuine ambiguity).
bool newIsStandardProtocol = isProtocolAttribute && etName == "I" + nativeName;
bool existingIsStandardProtocol = protocolEntries.Contains (nativeName);
if (newIsStandardProtocol && !existingIsStandardProtocol) {
typeMap [nativeName] = entry;
protocolEntries.Add (nativeName);
} else if (!newIsStandardProtocol && existingIsStandardProtocol) {
// existing is the standard protocol, keep it
} else {
// genuine collision, drop both
typeMap.Remove (nativeName);
protocolEntries.Remove (nativeName);
}
} else {
typeMap.Add (nativeName, entry);
if (isProtocolAttribute && etName == "I" + nativeName)
protocolEntries.Add (nativeName);
}
map.Add (nativeName, (etNamespace + "." + etName, etNamespace, etName));
}

return typeMap.Count > 0;
Expand Down
Loading