forked from dotnet/linker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mark generic arguments of dynamically accessed types passed as string (…
…dotnet#1566) * Mark dynamically accessed generic arguments * Clean test * Use MarkType for keeping generic args Enable ComplexTypeHandling tests * Use MarkTypeVisibleToReflection for generic arguments Clean tests * MarkType always * Check for array types in TypeNameResolver * Mark System.Array instead of its element type * Whitespace * PR feedback * Pattern match Whitespace * Add extension method ResolveToMainTypeDefinition * Add comment * Use ResolveToMainTypeDefinition
- Loading branch information
Showing
8 changed files
with
329 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 53 additions & 43 deletions
96
src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
193 changes: 193 additions & 0 deletions
193
test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more 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.DataFlow | ||
{ | ||
public class ComplexTypeHandling | ||
{ | ||
public static void Main () | ||
{ | ||
TestArray (); | ||
TestArrayOnGeneric (); | ||
TestGenericArray (); | ||
TestGenericArrayOnGeneric (); | ||
TestArrayGetTypeFromMethodParam (); | ||
TestArrayGetTypeFromField (); | ||
TestArrayTypeGetType (); | ||
TestArrayCreateInstanceByName (); | ||
TestArrayInAttributeParameter (); | ||
} | ||
|
||
[Kept] | ||
class ArrayElementType | ||
{ | ||
public ArrayElementType () { } | ||
|
||
public void PublicMethod () { } | ||
|
||
private int _privateField; | ||
} | ||
|
||
[Kept] | ||
static void TestArray () | ||
{ | ||
RequirePublicMethods (typeof (ArrayElementType[])); | ||
} | ||
|
||
[Kept] | ||
static void TestGenericArray () | ||
{ | ||
RequirePublicMethodsOnArrayOfGeneric<ArrayElementType> (); | ||
} | ||
|
||
[Kept] | ||
static void RequirePublicMethodsOnArrayOfGeneric<T> () | ||
{ | ||
RequirePublicMethods (typeof (T[])); | ||
} | ||
|
||
[Kept] | ||
class ArrayElementInGenericType | ||
{ | ||
public ArrayElementInGenericType () { } | ||
|
||
public void PublicMethod () { } | ||
|
||
private int _privateField; | ||
} | ||
|
||
[Kept] | ||
[KeptMember (".ctor()")] | ||
class RequirePublicMethodsGeneric< | ||
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] | ||
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] | ||
T> | ||
{ | ||
} | ||
|
||
[Kept] | ||
static void TestArrayOnGeneric () | ||
{ | ||
_ = new RequirePublicMethodsGeneric<ArrayElementInGenericType[]> (); | ||
} | ||
|
||
[Kept] | ||
static void TestGenericArrayOnGeneric () | ||
{ | ||
RequirePublicMethodsOnArrayOfGenericParameter<ArrayElementInGenericType> (); | ||
} | ||
|
||
[Kept] | ||
static void RequirePublicMethodsOnArrayOfGenericParameter<T> () | ||
{ | ||
_ = new RequirePublicMethodsGeneric<T[]> (); | ||
} | ||
|
||
[Kept] | ||
sealed class ArrayGetTypeFromMethodParamElement | ||
{ | ||
// This 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 | ||
{ | ||
// This 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 | ||
{ | ||
// This 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[]")); | ||
} | ||
|
||
// Nothing should be marked as CreateInstance doesn't work on arrays | ||
class ArrayCreateInstanceByNameElement | ||
{ | ||
public ArrayCreateInstanceByNameElement () | ||
{ | ||
} | ||
} | ||
|
||
[Kept] | ||
static void TestArrayCreateInstanceByName () | ||
{ | ||
Activator.CreateInstance ("test", "Mono.Linker.Tests.Cases.DataFlow.ComplexTypeHandling+ArrayCreateInstanceByNameElement[]"); | ||
} | ||
|
||
[Kept] | ||
class ArrayInAttributeParamElement | ||
{ | ||
// This 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) | ||
{ | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters