diff --git a/tests/linker/ios/link all/LinkAllTest.cs b/tests/linker/ios/link all/LinkAllTest.cs index c51214351f84..f857d5fbfb1f 100644 --- a/tests/linker/ios/link all/LinkAllTest.cs +++ b/tests/linker/ios/link all/LinkAllTest.cs @@ -574,6 +574,23 @@ void CheckAsyncTaskMethodBuilder (Type atmb) Assert.Null (oifd, atmb.FullName + ".ObjectIdForDebugger"); #endif } + + [Test] + public void LinkedAwayGenericTypeAsOptionalMemberInProtocol () + { + // https://github.com/xamarin/xamarin-macios/issues/3523 + // This test will fail at build time if it regresses (usually these types of build tests go into monotouch-test, but monotouch-test uses NSSet elsewhere, which this test requires to be linked away). + Assert.IsNull (typeof (NSObject).Assembly.GetType (NamespacePrefix + "Foundation.NSSet`1"), "NSSet must be linked away, otherwise this test is useless"); + } + + [Protocol (Name = "ProtocolWithGenericsInOptionalMember", WrapperType = typeof (ProtocolWithGenericsInOptionalMemberWrapper))] + [ProtocolMember (IsRequired = false, IsProperty = false, IsStatic = false, Name = "ConfigureView", Selector = "configureViewForParameters:", ParameterType = new Type [] { typeof (global::Foundation.NSSet) }, ParameterByRef = new bool [] { false })] + public interface IProtocolWithGenericsInOptionalMember : INativeObject, IDisposable { } + + internal sealed class ProtocolWithGenericsInOptionalMemberWrapper : BaseWrapper, IProtocolWithGenericsInOptionalMember + { + public ProtocolWithGenericsInOptionalMemberWrapper (IntPtr handle, bool owns) : base (handle, owns) { } + } } [Introduced (PlatformName.MacOSX, 1, 0, PlatformArchitecture.Arch64)] diff --git a/tests/linker/ios/link all/link all.csproj b/tests/linker/ios/link all/link all.csproj index a1df95e8e41b..620537aa8350 100644 --- a/tests/linker/ios/link all/link all.csproj +++ b/tests/linker/ios/link all/link all.csproj @@ -39,7 +39,7 @@ mideast,other i386, x86_64 LINKALL;;$(DefineConstants) - --optimize=all,-remove-dynamic-registrar + --registrar:static --optimize=all,-remove-dynamic-registrar true diff --git a/tools/common/StaticRegistrar.cs b/tools/common/StaticRegistrar.cs index 80bdad790ea3..e0e9e8872ef4 100644 --- a/tools/common/StaticRegistrar.cs +++ b/tools/common/StaticRegistrar.cs @@ -482,6 +482,8 @@ TypeDefinition ResolveType (TypeReference tr) // this method if there's an actual need. if (tr is ArrayType arrayType) { return arrayType.ElementType.Resolve (); + } else if (tr is GenericInstanceType git) { + return ResolveType (git.ElementType); } else { var td = tr.Resolve (); if (td == null)