Skip to content

Commit

Permalink
Add test cases for complex type data flow tests
Browse files Browse the repository at this point in the history
Mostly array resolution issue related to dotnet#1566
  • Loading branch information
vitek-karas committed Oct 22, 2020
1 parent 3f21706 commit 4c10cf6
Showing 1 changed file with 104 additions and 8 deletions.
112 changes: 104 additions & 8 deletions test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public static void Main ()
TestArrayOnGeneric ();
TestGenericArray ();
TestGenericArrayOnGeneric ();
TestArrayGetTypeFromMethodParam ();
TestArrayGetTypeFromField ();
TestArrayTypeGetType ();
TestArrayCreateInstanceByName ();
TestArrayInAttributeParameter ();
}

[Kept]
Expand Down Expand Up @@ -52,14 +57,6 @@ static void RequirePublicMethodsOnArrayOfGeneric<T> ()
RequirePublicMethods (typeof (T[]));
}

[Kept]
private static void RequirePublicMethods (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
[KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))]
Type type)
{
}

[Kept]
class ArrayElementInGenericType
{
Expand Down Expand Up @@ -96,5 +93,104 @@ static void RequirePublicMethodsOnArrayOfGenericParameter<T> ()
{
_ = new RequirePublicMethodsGeneric<T[]> ();
}

[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)
{
}
}
}
}

0 comments on commit 4c10cf6

Please sign in to comment.