Skip to content

Commit

Permalink
Add test cases for complex type data flow tests (dotnet/linker#1580)
Browse files Browse the repository at this point in the history
Mostly array resolution issue related to dotnet/linker#1566

Commit migrated from dotnet/linker@2699ffa
  • Loading branch information
vitek-karas authored Oct 22, 2020
1 parent 85db0b4 commit 26eb08b
Showing 1 changed file with 104 additions and 8 deletions.
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 26eb08b

Please sign in to comment.