diff options
author | Vitek Karas <vitek.karas@microsoft.com> | 2021-04-12 14:04:20 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-12 14:04:20 +0300 |
commit | 6bfa2c0657d2dcfd6dce684ab34b470ce567631a (patch) | |
tree | ec604b198fb715777dc948086794042ae85ed4ca /test/Mono.Linker.Tests.Cases/DataFlow | |
parent | 6944b7c146a7149c108acad19b237a29fd2eed15 (diff) |
Expression.Call can act as MakeGenericMethod so make it perform same validation (#1930)
Also improved validation done by MakeGenericMethod to avoid warning if no type arguments are passed in.
Added tests.
Diffstat (limited to 'test/Mono.Linker.Tests.Cases/DataFlow')
-rw-r--r-- | test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs index 7872462f7..08bb958cd 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs @@ -882,12 +882,14 @@ namespace Mono.Linker.Tests.Cases.DataFlow { TestNullMethod (); TestUnknownInput (null); + TestUnknownMethodButNoTypeArguments (null); TestWithNoArguments (); TestWithRequirements (); TestWithRequirementsFromParam (null); TestWithRequirementsFromGenericParam<TestType> (); TestWithRequirementsViaRuntimeMethod (); + TestWithRequirementsButNoTypeArguments (); TestWithNoRequirements (); TestWithNoRequirementsFromParam (null); @@ -914,6 +916,14 @@ namespace Mono.Linker.Tests.Cases.DataFlow mi.MakeGenericMethod (typeof (TestType)); } + [UnrecognizedReflectionAccessPattern (typeof (MethodInfo), nameof (MethodInfo.MakeGenericMethod), new Type[] { typeof (Type[]) }, + messageCode: "IL2060")] + static void TestUnknownMethodButNoTypeArguments (MethodInfo mi) + { + // Thechnically linker could figure this out, but it's not worth the complexity - such call will always fail at runtime. + mi.MakeGenericMethod (Type.EmptyTypes); + } + [RecognizedReflectionAccessPattern] static void TestWithNoArguments () { @@ -957,6 +967,15 @@ namespace Mono.Linker.Tests.Cases.DataFlow .MakeGenericMethod (typeof (TestType)); } + [UnrecognizedReflectionAccessPattern (typeof (MethodInfo), nameof (MethodInfo.MakeGenericMethod), new Type[] { typeof (Type[]) }, + messageCode: "IL2060")] + static void TestWithRequirementsButNoTypeArguments () + { + // Linker could figure out that this is not a problem, but it's not worth the complexity, since this will always throw at runtime + typeof (MakeGenericMethod).GetMethod (nameof (GenericWithRequirements), BindingFlags.Static) + .MakeGenericMethod (Type.EmptyTypes); + } + public static void GenericWithRequirements<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] T> () { } |