Add more tests that have been enabled by recent changes (#73175)
authorTlakaelel Axayakatl Ceja <tlakaelel_axayakatl@outlook.com>
Mon, 1 Aug 2022 22:26:20 +0000 (15:26 -0700)
committerGitHub <noreply@github.com>
Mon, 1 Aug 2022 22:26:20 +0000 (15:26 -0700)
src/coreclr/tools/aot/Mono.Linker.Tests.Cases/RequiresCapability/Dependencies/RequiresInCopyAssembly.cs [new file with mode: 0644]
src/coreclr/tools/aot/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityFromCopiedAssembly.cs [new file with mode: 0644]
src/coreclr/tools/aot/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityReflectionAnalysisEnabled.cs [new file with mode: 0644]
src/coreclr/tools/aot/Mono.Linker.Tests.Cases/RequiresCapability/RequiresViaDataflow.cs [new file with mode: 0644]
src/coreclr/tools/aot/Mono.Linker.Tests.Cases/RequiresCapability/RequiresWithCopyAssembly.cs [new file with mode: 0644]
src/coreclr/tools/aot/Mono.Linker.Tests.Cases/RequiresCapability/SuppressRequires.cs [new file with mode: 0644]

diff --git a/src/coreclr/tools/aot/Mono.Linker.Tests.Cases/RequiresCapability/Dependencies/RequiresInCopyAssembly.cs b/src/coreclr/tools/aot/Mono.Linker.Tests.Cases/RequiresCapability/Dependencies/RequiresInCopyAssembly.cs
new file mode 100644 (file)
index 0000000..c0b8f7b
--- /dev/null
@@ -0,0 +1,123 @@
+// Copyright (c) .NET Foundation and contributors. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using System.Diagnostics.CodeAnalysis;
+using System.Runtime.CompilerServices;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Metadata;
+
+namespace Mono.Linker.Tests.Cases.RequiresCapability.Dependencies
+{
+       public class RequiresInCopyAssembly
+       {
+               public RequiresInCopyAssembly ()
+               {
+               }
+
+               [RequiresUnreferencedCode ("Message for --Method--")]
+               [RequiresAssemblyFiles ("Message for --Method--")]
+               [RequiresDynamicCode ("Message for --Method--")]
+               public void Method ()
+               {
+               }
+
+               [RequiresUnreferencedCode ("Message for --UncalledMethod--")]
+               [RequiresAssemblyFiles ("Message for --UncalledMethod--")]
+               [RequiresDynamicCode ("Message for --UncalledMethod--")]
+               public void UncalledMethod ()
+               {
+               }
+
+               [RequiresUnreferencedCode ("Message for --MethodCalledThroughReflection--")]
+               [RequiresAssemblyFiles ("Message for --MethodCalledThroughReflection--")]
+               [RequiresDynamicCode ("Message for --MethodCalledThroughReflection--")]
+               static void MethodCalledThroughReflection ()
+               {
+               }
+
+               public int UnusedProperty {
+                       [RequiresUnreferencedCode ("Message for --getter UnusedProperty--")]
+                       [RequiresAssemblyFiles ("Message for --getter UnusedProperty--")]
+                       [RequiresDynamicCode ("Message for --getter UnusedProperty--")]
+                       get { return 42; }
+
+                       [RequiresUnreferencedCode ("Message for --setter UnusedProperty--")]
+                       [RequiresAssemblyFiles ("Message for --setter UnusedProperty--")]
+                       [RequiresDynamicCode ("Message for --setter UnusedProperty--")]
+                       set { }
+               }
+
+               class UnusedBaseType
+               {
+                       [RequiresUnreferencedCode ("Message for --UnusedBaseTypeCctor--")]
+                       [RequiresAssemblyFiles ("Message for --UnusedBaseTypeCctor--")]
+                       [RequiresDynamicCode ("Message for --UnusedBaseTypeCctor--")]
+                       static UnusedBaseType ()
+                       {
+                       }
+
+                       [RequiresUnreferencedCode ("Message for --UnusedVirtualMethod1--")]
+                       [RequiresAssemblyFiles ("Message for --UnusedVirtualMethod1--")]
+                       [RequiresDynamicCode ("Message for --UnusedVirtualMethod1--")]
+                       public virtual void UnusedVirtualMethod1 ()
+                       {
+                       }
+
+                       [RequiresUnreferencedCode ("Message for --UnusedVirtualMethod2--")]
+                       [RequiresAssemblyFiles ("Message for --UnusedVirtualMethod2--")]
+                       [RequiresDynamicCode ("Message for --UnusedVirtualMethod2--")]
+                       public virtual void UnusedVirtualMethod2 ()
+                       {
+                       }
+               }
+
+               class UnusedDerivedType : UnusedBaseType
+               {
+                       [RequiresUnreferencedCode ("Message for --UnusedVirtualMethod1--")]
+                       [RequiresAssemblyFiles ("Message for --UnusedVirtualMethod1--")]
+                       [RequiresDynamicCode ("Message for --UnusedVirtualMethod1--")]
+                       public override void UnusedVirtualMethod1 ()
+                       {
+                       }
+
+                       // Should not warn when this is part of a copied assembly.
+                       public override void UnusedVirtualMethod2 ()
+                       {
+                       }
+               }
+
+               interface IUnusedInterface
+               {
+                       [RequiresUnreferencedCode ("Message for --IUnusedInterface.UnusedMethod--")]
+                       [RequiresAssemblyFiles ("Message for --IUnusedInterface.UnusedMethod--")]
+                       [RequiresDynamicCode ("Message for --IUnusedInterface.UnusedMethod--")]
+                       public void UnusedMethod ();
+               }
+
+               class UnusedImplementationClass : IUnusedInterface
+               {
+                       [RequiresUnreferencedCode ("Message for --UnusedImplementationClass.UnusedMethod--")]
+                       [RequiresAssemblyFiles ("Message for --UnusedImplementationClass.UnusedMethod--")]
+                       [RequiresDynamicCode ("Message for --UnusedImplementationClass.UnusedMethod--")]
+                       public void UnusedMethod ()
+                       {
+                       }
+               }
+
+               public interface IBaseInterface
+               {
+                       [RequiresUnreferencedCode ("Message for --IBaseInterface.MethodInBaseInterface--")]
+                       [RequiresAssemblyFiles ("Message for --IBaseInterface.MethodInBaseInterface--")]
+                       [RequiresDynamicCode ("Message for --IBaseInterface.MethodInBaseInterface--")]
+                       void MethodInBaseInterface ();
+               }
+
+               public interface IDerivedInterface : IBaseInterface
+               {
+                       [RequiresUnreferencedCode ("Message for --IDerivedInterface.MethodInDerivedInterface--")]
+                       [RequiresAssemblyFiles ("Message for --IDerivedInterface.MethodInDerivedInterface--")]
+                       [RequiresDynamicCode ("Message for --IDerivedInterface.MethodInDerivedInterface--")]
+                       void MethodInDerivedInterface ();
+               }
+       }
+}
diff --git a/src/coreclr/tools/aot/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityFromCopiedAssembly.cs b/src/coreclr/tools/aot/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityFromCopiedAssembly.cs
new file mode 100644 (file)
index 0000000..653f794
--- /dev/null
@@ -0,0 +1,29 @@
+// Copyright (c) .NET Foundation and contributors. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Metadata;
+using Mono.Linker.Tests.Cases.RequiresCapability.Dependencies;
+
+namespace Mono.Linker.Tests.Cases.RequiresCapability
+{
+       [SetupLinkerAction ("copy", "lib")]
+       [SetupCompileBefore ("lib.dll", new[] { "Dependencies/RequiresInCopyAssembly.cs" })]
+       [KeptAllTypesAndMembersInAssembly ("lib.dll")]
+       [LogDoesNotContain ("IL2026")]
+       [LogDoesNotContain ("IL3002")]
+       [LogDoesNotContain ("IL2027")]
+       public class RequiresCapabilityFromCopiedAssembly
+       {
+               public static void Main ()
+               {
+                       Test ();
+               }
+
+               [Kept]
+               static void Test ()
+               {
+                       var x = new RequiresInCopyAssembly ();
+               }
+       }
+}
diff --git a/src/coreclr/tools/aot/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityReflectionAnalysisEnabled.cs b/src/coreclr/tools/aot/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityReflectionAnalysisEnabled.cs
new file mode 100644 (file)
index 0000000..856c3d4
--- /dev/null
@@ -0,0 +1,143 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.Text;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Helpers;
+using Mono.Linker.Tests.Cases.Expectations.Metadata;
+
+namespace Mono.Linker.Tests.Cases.RequiresCapability
+{
+       [ExpectedNoWarnings]
+       public class RequiresCapabilityReflectionAnalysisEnabled
+       {
+               [LogContains ("-- DynamicallyAccessedMembersEnabled --")]
+               [LogContains ("-- ReflectionPattern --")]
+               [LogContains ("-- DynamicallyAccessedMembersOnGenericsEnabled --")]
+               public static void Main ()
+               {
+                       TestRequiresAttributeWithDynamicallyAccessedMembersEnabled ();
+                       TestRequiresAttributeWithReflectionPattern ();
+                       TestRequiresAttributeWithDynamicallyAccessedMembersOnGenericsEnabled ();
+                       TestRequiresAndDynamicallyAccessedMembers.Test ();
+               }
+
+               [Kept]
+               [KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
+               [RequiresUnreferencedCode ("-- DynamicallyAccessedMembersEnabled --")]
+               static void TestRequiresAttributeWithDynamicallyAccessedMembersEnabled ()
+               {
+                       typeof (TypeWithPublicFieldsAccessed).RequiresPublicFields ();
+               }
+
+               [Kept]
+               class TypeWithPublicFieldsAccessed
+               {
+                       [Kept]
+                       public int _publicField;
+
+                       private int _privateField;
+               }
+
+               [Kept]
+               [KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
+               [RequiresUnreferencedCode ("-- ReflectionPattern --")]
+               static void TestRequiresAttributeWithReflectionPattern ()
+               {
+                       typeof (TypeWithMethodAccessed).GetMethod ("PublicMethod");
+               }
+
+               [Kept]
+               class TypeWithMethodAccessed
+               {
+                       [Kept]
+                       public void PublicMethod () { }
+
+                       public void PublicMethod2 () { }
+               }
+
+               [Kept]
+               [KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
+               [RequiresUnreferencedCode ("-- DynamicallyAccessedMembersOnGenericsEnabled --")]
+               static void TestRequiresAttributeWithDynamicallyAccessedMembersOnGenericsEnabled ()
+               {
+                       TypeRequiresPublicFields<TypeWithPublicFieldsForGenericType>.Method ();
+                       MethodRequiresPublicFields<TypeWithPublicFieldsForGenericMethod> ();
+               }
+
+               [Kept]
+               class TypeRequiresPublicFields<
+                       [KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
+               [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)]
+               T>
+               {
+                       [Kept]
+                       public static void Method () { }
+               }
+
+               [Kept]
+               class TypeWithPublicFieldsForGenericType
+               {
+                       [Kept]
+                       public int _publicField;
+
+                       private int _privateField;
+               }
+
+               [Kept]
+               static void MethodRequiresPublicFields<
+                       [KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
+               [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)]
+               T> ()
+               {
+               }
+
+               [Kept]
+               class TypeWithPublicFieldsForGenericMethod
+               {
+                       [Kept]
+                       public int _publicField;
+
+                       private int _privateField;
+               }
+
+               [Kept]
+               class TestRequiresAndDynamicallyAccessedMembers
+               {
+                       [Kept]
+                       [KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
+                       [RequiresUnreferencedCode ("--- RequiresAndPublicMethods ---")]
+                       static void RequiresAndPublicMethods (
+                               [KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))]
+                               [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
+                               Type type)
+                       {
+                               // This should not produce a warning since the method is annotated with Requires
+                               type.RequiresPublicFields ();
+
+                               // This will still "work" in that it will apply the PublicFields requirement onto the specified type
+                               typeof (TestRequiresAndDynamicallyAccessedMembers).RequiresPublicFields ();
+                       }
+
+                       [Kept]
+                       public void PublicInstanceMethod () { }
+
+                       [Kept]
+                       public static void PublicStaticMethod () { }
+
+                       static void PrivateInstanceMethod () { }
+
+                       [Kept]
+                       public static int PublicStaticField;
+
+                       static int PrivateStaticField;
+
+                       [Kept]
+                       [ExpectedWarning ("IL2026", "--- RequiresAndPublicMethods ---")]
+                       public static void Test ()
+                       {
+                               RequiresAndPublicMethods (typeof (TestRequiresAndDynamicallyAccessedMembers));
+                       }
+               }
+       }
+}
\ No newline at end of file
diff --git a/src/coreclr/tools/aot/Mono.Linker.Tests.Cases/RequiresCapability/RequiresViaDataflow.cs b/src/coreclr/tools/aot/Mono.Linker.Tests.Cases/RequiresCapability/RequiresViaDataflow.cs
new file mode 100644 (file)
index 0000000..775b581
--- /dev/null
@@ -0,0 +1,79 @@
+// Copyright (c) .NET Foundation and contributors. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+
+namespace Mono.Linker.Tests.Cases.RequiresCapability
+{
+       [SkipKeptItemsValidation]
+       [ExpectedNoWarnings]
+       class RequiresViaDataflow
+       {
+               // Base/Derived and Implementation/Interface differs between linker and analyzer https://github.com/dotnet/linker/issues/2533
+               [ExpectedWarning ("IL2026", "--DynamicallyAccessedTypeWithRequires.MethodWithRequires--")]
+               [ExpectedWarning ("IL2026", "TypeWhichOverridesMethod.VirtualMethodRequires()", "--TypeWhichOverridesMethod.VirtualMethodRequires--", ProducedBy = ProducedBy.Analyzer | ProducedBy.NativeAot)]
+               [ExpectedWarning ("IL2026", "BaseType.VirtualMethodRequires()", "--BaseType.VirtualMethodRequires--")]
+               public static void Main ()
+               {
+                       TestDynamicallyAccessedMembersWithRequires (typeof (DynamicallyAccessedTypeWithRequires));
+                       TestDynamicallyAccessedMembersWithRequires (typeof (TypeWhichOverridesMethod));
+                       TestRequiresInDynamicDependency ();
+               }
+
+               class BaseType
+               {
+                       [RequiresUnreferencedCode ("Message for --BaseType.VirtualMethodRequires--")]
+                       [RequiresAssemblyFiles ("Message for --BaseType.VirtualMethodRequires--")]
+                       [RequiresDynamicCode ("Message for --BaseType.VirtualMethodRequires--")]
+                       public virtual void VirtualMethodRequires ()
+                       {
+                       }
+               }
+
+               class TypeWhichOverridesMethod : BaseType
+               {
+                       [RequiresUnreferencedCode ("Message for --TypeWhichOverridesMethod.VirtualMethodRequires--")]
+                       [RequiresAssemblyFiles ("Message for --TypeWhichOverridesMethod.VirtualMethodRequires--")]
+                       [RequiresDynamicCode ("Message for --TypeWhichOverridesMethod.VirtualMethodRequires--")]
+                       public override void VirtualMethodRequires ()
+                       {
+                       }
+               }
+
+               public class DynamicallyAccessedTypeWithRequires
+               {
+                       [RequiresUnreferencedCode ("Message for --DynamicallyAccessedTypeWithRequires.MethodWithRequires--")]
+                       public void MethodWithRequires ()
+                       {
+                       }
+               }
+
+               static void TestDynamicallyAccessedMembersWithRequires (
+                       [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type type)
+               {
+               }
+
+               [RequiresUnreferencedCode ("Message for --RequiresInDynamicDependency--")]
+               [RequiresAssemblyFiles ("Message for --RequiresInDynamicDependency--")]
+               [RequiresDynamicCode ("Message for --RequiresInDynamicDependency--")]
+               static void RequiresInDynamicDependency ()
+               {
+               }
+
+               [ExpectedWarning ("IL2026", "--RequiresInDynamicDependency--")]
+               [ExpectedWarning ("IL2026", "--RequiresInDynamicDependency--", ProducedBy = ProducedBy.Trimmer)]
+               [ExpectedWarning ("IL3002", "--RequiresInDynamicDependency--", ProducedBy = ProducedBy.Analyzer | ProducedBy.NativeAot)]
+               [ExpectedWarning ("IL3050", "--RequiresInDynamicDependency--", ProducedBy = ProducedBy.Analyzer | ProducedBy.NativeAot)]
+               [DynamicDependency ("RequiresInDynamicDependency")]
+               static void TestRequiresInDynamicDependency ()
+               {
+                       RequiresInDynamicDependency ();
+               }
+       }
+}
diff --git a/src/coreclr/tools/aot/Mono.Linker.Tests.Cases/RequiresCapability/RequiresWithCopyAssembly.cs b/src/coreclr/tools/aot/Mono.Linker.Tests.Cases/RequiresCapability/RequiresWithCopyAssembly.cs
new file mode 100644 (file)
index 0000000..873751a
--- /dev/null
@@ -0,0 +1,66 @@
+// Copyright (c) .NET Foundation and contributors. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Metadata;
+using Mono.Linker.Tests.Cases.RequiresCapability.Dependencies;
+
+namespace Mono.Linker.Tests.Cases.RequiresCapability
+{
+       [SetupLinkerAction ("copy", "lib")]
+       [SetupCompileBefore ("lib.dll", new[] { "Dependencies/RequiresInCopyAssembly.cs" })]
+       [KeptAllTypesAndMembersInAssembly ("lib.dll")]
+       [SkipKeptItemsValidation]
+       // Annotated members on a copied assembly should not produce any warnings
+       // unless directly called or referenced through reflection.
+       [LogDoesNotContain ("--UncalledMethod--")]
+       [LogDoesNotContain ("--getter UnusedProperty--")]
+       [LogDoesNotContain ("--setter UnusedProperty--")]
+       [LogDoesNotContain ("--UnusedBaseTypeCctor--")]
+       [LogDoesNotContain ("--UnusedVirtualMethod1--")]
+       [LogDoesNotContain ("--UnusedVirtualMethod2--")]
+       [LogDoesNotContain ("--IUnusedInterface.UnusedMethod--")]
+       [LogDoesNotContain ("--UnusedImplementationClass.UnusedMethod--")]
+       // [LogDoesNotContain ("UnusedVirtualMethod2")] // https://github.com/dotnet/linker/issues/2106
+
+       [ExpectedNoWarnings]
+       class RequiresWithCopyAssembly
+       {
+               [ExpectedWarning ("IL2026", "--IDerivedInterface.MethodInDerivedInterface--")]
+               [ExpectedWarning ("IL2026", "--IBaseInterface.MethodInBaseInterface--")]
+               public static void Main ()
+               {
+                       TestRequiresInMethodFromCopiedAssembly ();
+                       TestRequiresThroughReflectionInMethodFromCopiedAssembly ();
+                       TestRequiresInDynamicallyAccessedMethodFromCopiedAssembly (typeof (RequiresInCopyAssembly.IDerivedInterface));
+               }
+
+               [ExpectedWarning ("IL2026", "--Method--")]
+               [ExpectedWarning ("IL3002", "--Method--", ProducedBy = ProducedBy.Analyzer | ProducedBy.NativeAot)]
+               [ExpectedWarning ("IL3050", "--Method--", ProducedBy = ProducedBy.Analyzer | ProducedBy.NativeAot)]
+               static void TestRequiresInMethodFromCopiedAssembly ()
+               {
+                       var tmp = new RequiresInCopyAssembly ();
+                       tmp.Method ();
+               }
+
+               [ExpectedWarning ("IL2026", "--MethodCalledThroughReflection--")]
+               static void TestRequiresThroughReflectionInMethodFromCopiedAssembly ()
+               {
+                       typeof (RequiresInCopyAssembly)
+                               .GetMethod ("MethodCalledThroughReflection", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)
+                               .Invoke (null, new object[0]);
+               }
+
+               static void TestRequiresInDynamicallyAccessedMethodFromCopiedAssembly (
+               [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] Type type)
+               {
+               }
+       }
+}
diff --git a/src/coreclr/tools/aot/Mono.Linker.Tests.Cases/RequiresCapability/SuppressRequires.cs b/src/coreclr/tools/aot/Mono.Linker.Tests.Cases/RequiresCapability/SuppressRequires.cs
new file mode 100644 (file)
index 0000000..fbffac3
--- /dev/null
@@ -0,0 +1,160 @@
+// Copyright (c) .NET Foundation and contributors. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Helpers;
+
+namespace Mono.Linker.Tests.Cases.RequiresCapability
+{
+       [SkipKeptItemsValidation]
+       [ExpectedNoWarnings]
+       class SuppressRequires
+       {
+               public static void Main ()
+               {
+                       SuppressMethodBodyReferences.Test ();
+                       SuppressGenericParameters<TestType, TestType>.Test ();
+               }
+
+               class SuppressMethodBodyReferences
+               {
+                       static Type _unknownType;
+                       static Type GetUnknownType () => null;
+
+                       [RequiresUnreferencedCode ("Message for --MethodWithRequires--")]
+                       [RequiresAssemblyFiles ("Message for --MethodWithRequires--")]
+                       [RequiresDynamicCode ("Message for --MethodWithRequires--")]
+                       static void MethodWithRequires ()
+                       {
+                       }
+
+                       [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
+                       static Type _requiresPublicConstructors;
+
+                       [RequiresUnreferencedCode ("")]
+                       [RequiresAssemblyFiles ("")]
+                       [RequiresDynamicCode ("")]
+                       static void TestMethodWithRequires ()
+                       {
+                               // Normally this would warn, but with the attribute on this method it should be auto-suppressed
+                               MethodWithRequires ();
+                       }
+
+                       [RequiresUnreferencedCode ("")]
+                       [RequiresAssemblyFiles ("")]
+                       [RequiresDynamicCode ("")]
+                       static void TestParameter ()
+                       {
+                               _unknownType.RequiresPublicMethods ();
+                       }
+
+                       [RequiresUnreferencedCode ("")]
+                       [RequiresAssemblyFiles ("")]
+                       [RequiresDynamicCode ("")]
+                       static void TestReturnValue ()
+                       {
+                               GetUnknownType ().RequiresPublicEvents ();
+                       }
+
+                       [RequiresUnreferencedCode ("")]
+                       [RequiresAssemblyFiles ("")]
+                       [RequiresDynamicCode ("")]
+                       static void TestField ()
+                       {
+                               _requiresPublicConstructors = _unknownType;
+                       }
+
+                       [UnconditionalSuppressMessage ("Trimming", "IL2026")]
+                       [UnconditionalSuppressMessage ("SingleFile", "IL3002")]
+                       [UnconditionalSuppressMessage ("AOT", "IL3050")]
+                       public static void Test ()
+                       {
+                               TestMethodWithRequires ();
+                               TestParameter ();
+                               TestReturnValue ();
+                               TestField ();
+                       }
+               }
+
+               [ExpectedNoWarnings]
+               class SuppressGenericParameters<TUnknown, [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicProperties)] TPublicProperties>
+               {
+                       static Type _unknownType;
+
+                       static void GenericMethodRequiresPublicMethods<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] T> () { }
+
+                       class GenericTypeRequiresPublicFields<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] T> { }
+
+                       [RequiresUnreferencedCode ("")]
+                       [RequiresAssemblyFiles ("")]
+                       [RequiresDynamicCode ("")]
+                       static void TestGenericMethod ()
+                       {
+                               GenericMethodRequiresPublicMethods<TUnknown> ();
+                       }
+
+                       [RequiresUnreferencedCode ("")]
+                       [RequiresAssemblyFiles ("")]
+                       [RequiresDynamicCode ("")]
+                       static void TestGenericMethodMismatch ()
+                       {
+                               GenericMethodRequiresPublicMethods<TPublicProperties> ();
+                       }
+
+                       [RequiresUnreferencedCode ("")]
+                       [RequiresAssemblyFiles ("")]
+                       [RequiresDynamicCode ("")]
+                       static void TestGenericType ()
+                       {
+                               new GenericTypeRequiresPublicFields<TUnknown> ();
+                       }
+
+                       [RequiresUnreferencedCode ("")]
+                       [RequiresAssemblyFiles ("")]
+                       [RequiresDynamicCode ("")]
+                       static void TestMakeGenericTypeWithStaticTypes ()
+                       {
+                               typeof (GenericTypeRequiresPublicFields<>).MakeGenericType (typeof (TUnknown));
+                       }
+
+                       [RequiresUnreferencedCode ("")]
+                       [RequiresAssemblyFiles ("")]
+                       [RequiresDynamicCode ("")]
+                       static void TestMakeGenericTypeWithDynamicTypes ()
+                       {
+                               typeof (GenericTypeRequiresPublicFields<>).MakeGenericType (_unknownType);
+                       }
+
+                       [RequiresUnreferencedCode ("")]
+                       [RequiresAssemblyFiles ("")]
+                       [RequiresDynamicCode ("")]
+                       static void TestMakeGenericMethod ()
+                       {
+                               typeof (SuppressGenericParameters<TUnknown, TPublicProperties>)
+                                       .GetMethod ("GenericMethodRequiresPublicMethods", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)
+                                       .MakeGenericMethod (typeof (TPublicProperties));
+                       }
+
+                       [UnconditionalSuppressMessage ("Trimming", "IL2026")]
+                       [UnconditionalSuppressMessage ("SingleFile", "IL3002")]
+                       [UnconditionalSuppressMessage ("AOT", "IL3050")]
+                       public static void Test ()
+                       {
+                               TestGenericMethod ();
+                               TestGenericMethodMismatch ();
+                               TestGenericType ();
+                               TestMakeGenericTypeWithStaticTypes ();
+                               TestMakeGenericTypeWithDynamicTypes ();
+                               TestMakeGenericMethod ();
+                       }
+               }
+
+               class TestType { }
+       }
+}