From 26eb08b15f4d8bef2798c7c58257385155175028 Mon Sep 17 00:00:00 2001 From: Vitek Karas Date: Thu, 22 Oct 2020 08:26:31 -0700 Subject: [PATCH] Add test cases for complex type data flow tests (dotnet/linker#1580) Mostly array resolution issue related to https://github.com/mono/linker/pull/1566 Commit migrated from https://github.com/dotnet/linker/commit/2699ffa72993e0d2c04e4e0d388be714b6f3a594 --- .../DataFlow/ComplexTypeHandling.cs | 112 ++++++++++++++++-- 1 file changed, 104 insertions(+), 8 deletions(-) diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs index e723b6a80d6a5..a86354bedcd37 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs @@ -21,6 +21,11 @@ public static void Main () TestArrayOnGeneric (); TestGenericArray (); TestGenericArrayOnGeneric (); + TestArrayGetTypeFromMethodParam (); + TestArrayGetTypeFromField (); + TestArrayTypeGetType (); + TestArrayCreateInstanceByName (); + TestArrayInAttributeParameter (); } [Kept] @@ -52,14 +57,6 @@ static void RequirePublicMethodsOnArrayOfGeneric () RequirePublicMethods (typeof (T[])); } - [Kept] - private static void RequirePublicMethods ( - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] - [KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))] - Type type) - { - } - [Kept] class ArrayElementInGenericType { @@ -96,5 +93,104 @@ static void RequirePublicMethodsOnArrayOfGenericParameter () { _ = new RequirePublicMethodsGeneric (); } + + [Kept] + sealed class ArrayGetTypeFromMethodParamElement + { + [Kept] // This is a bug - the method should not be marked, instead Array.* should be marked + public void PublicMethod () { } + } + + [Kept] + static void TestArrayGetTypeFromMethodParamHelper (ArrayGetTypeFromMethodParamElement[] p) + { + RequirePublicMethods (p.GetType ()); + } + + [Kept] + static void TestArrayGetTypeFromMethodParam () + { + TestArrayGetTypeFromMethodParamHelper (null); + } + + [Kept] + sealed class ArrayGetTypeFromFieldElement + { + [Kept] // This is a bug - the method should not be marked, instead Array.* should be marked + public void PublicMethod () { } + } + + [Kept] + static ArrayGetTypeFromFieldElement[] _arrayGetTypeFromField; + + [Kept] + static void TestArrayGetTypeFromField () + { + RequirePublicMethods (_arrayGetTypeFromField.GetType ()); + } + + [Kept] + sealed class ArrayTypeGetTypeElement + { + [Kept] // This is a bug - the method should not be marked, instead Array.* should be marked + public void PublicMethod () { } + } + + [Kept] + static void TestArrayTypeGetType () + { + RequirePublicMethods (Type.GetType ("Mono.Linker.Tests.Cases.DataFlow.ComplexTypeHandling+ArrayTypeGetTypeElement[]")); + } + + [Kept] + class ArrayCreateInstanceByNameElement + { + [Kept] // This is a bug - the .ctor should not be marked - in fact in this case nothing should be marked as CreateInstance doesn't work on arrays + public ArrayCreateInstanceByNameElement () + { + } + } + + [Kept] + static void TestArrayCreateInstanceByName () + { + Activator.CreateInstance ("test", "Mono.Linker.Tests.Cases.DataFlow.ComplexTypeHandling+ArrayCreateInstanceByNameElement[]"); + } + + [Kept] + class ArrayInAttributeParamElement + { + [Kept] // This is a bug - the method should not be marked, instead Array.* should be marked + public void PublicMethod () { } + } + + [Kept] + [KeptAttributeAttribute (typeof (RequiresPublicMethodAttribute))] + [RequiresPublicMethod (typeof (ArrayInAttributeParamElement[]))] + static void TestArrayInAttributeParameter () + { + } + + + [Kept] + private static void RequirePublicMethods ( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] + [KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))] + Type type) + { + } + + [Kept] + [KeptBaseType (typeof (Attribute))] + class RequiresPublicMethodAttribute : Attribute + { + [Kept] + public RequiresPublicMethodAttribute ( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] + [KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))] + Type t) + { + } + } } }