diff options
author | Vitek Karas <10670590+vitek-karas@users.noreply.github.com> | 2022-02-28 14:47:58 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-28 14:47:58 +0300 |
commit | f0bd2ae053b96af7a8dae429f9dc91f1ce28684b (patch) | |
tree | 1f9dae3f3fa386e21ca0d33b4ab50ef056d11b94 /test/Mono.Linker.Tests.Cases/DataFlow | |
parent | 45b481f3504fa3c7142ed22f37d2813b0c7df43f (diff) |
Share intrinsic handling of GetMember and similar APIs (#2639)
Other than sharing more code and adapting it so that it works on both linker and analyzer, this change brings simple analysis of constant integer values in the analyzer. This is necessary to make most reflection API calls recognize binding flags. For example `GetMethods(BindingFlags.Public | BindingFlags.Static)`. So this change adds analysis of constant values (as recognized by the Roslyn's operation tree) and the OR binary operator for integers and enums.
Added some new tests for the binding flags handling.
Reenabled some disabled tests for analyzer.
Moved the main affected tests from the generated source files to the hardcoded one and force them to exact match of warnings for both linker and analyzer.
Diffstat (limited to 'test/Mono.Linker.Tests.Cases/DataFlow')
-rw-r--r-- | test/Mono.Linker.Tests.Cases/DataFlow/AnnotatedMembersAccessedViaReflection.cs | 27 | ||||
-rw-r--r-- | test/Mono.Linker.Tests.Cases/DataFlow/DynamicDependencyDataflow.cs | 6 |
2 files changed, 11 insertions, 22 deletions
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/AnnotatedMembersAccessedViaReflection.cs b/test/Mono.Linker.Tests.Cases/DataFlow/AnnotatedMembersAccessedViaReflection.cs index 07a450776..ef5339d7f 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/AnnotatedMembersAccessedViaReflection.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/AnnotatedMembersAccessedViaReflection.cs @@ -39,8 +39,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] public static Type _annotatedField; - // Intrinsic is disabled https://github.com/dotnet/linker/issues/2559 - [ExpectedWarning ("IL2110", nameof (_annotatedField), ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2110", nameof (_annotatedField))] static void Reflection () { typeof (AnnotatedField).GetField ("_annotatedField").SetValue (null, typeof (TestType)); @@ -52,8 +51,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow typeof (AnnotatedField).GetField ("_annotatedField").SetValue (null, typeof (TestType)); } - // Intrinsic is disabled https://github.com/dotnet/linker/issues/2559 - [ExpectedWarning ("IL2110", nameof (_annotatedField), ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2110", nameof (_annotatedField))] static void ReflectionReadOnly () { typeof (AnnotatedField).GetField ("_annotatedField").GetValue (null); @@ -160,8 +158,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow { } } - // Intrinsic is disabled https://github.com/dotnet/linker/issues/2559 - [ExpectedWarning ("IL2111", nameof (MethodWithSingleAnnotatedParameter), ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2111", nameof (MethodWithSingleAnnotatedParameter))] static void Reflection () { typeof (AnnotatedMethodParameters).GetMethod (nameof (MethodWithSingleAnnotatedParameter)).Invoke (null, null); @@ -294,8 +291,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow typeof (AnnotatedMethodReturnValue).GetMethod (nameof (InstanceMethodWithAnnotatedReturnValue)).Invoke (null, null); } - // Intrinsic is disabled https://github.com/dotnet/linker/issues/2559 - [ExpectedWarning ("IL2111", nameof (VirtualMethodWithAnnotatedReturnValue), ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2111", nameof (VirtualMethodWithAnnotatedReturnValue))] static void ReflectionOnVirtual () { typeof (AnnotatedMethodReturnValue).GetMethod (nameof (VirtualMethodWithAnnotatedReturnValue)).Invoke (null, null); @@ -423,8 +419,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow public Type PropertyWithAnnotation { get; set; } } - // Intrinsic is disabled https://github.com/dotnet/linker/issues/2559 - [ExpectedWarning ("IL2111", nameof (Property1WithAnnotation) + ".set", ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2111", nameof (Property1WithAnnotation) + ".set")] static void ReflectionOnPropertyItself () { typeof (AnnotatedProperty).GetProperty (nameof (Property1WithAnnotation)); @@ -441,8 +436,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow typeof (AnnotatedProperty).GetProperty (nameof (Property2WithAnnotationGetterOnly)); } - // Intrinsic is disabled https://github.com/dotnet/linker/issues/2559 - [ExpectedWarning ("IL2111", nameof (VirtualProperty3WithAnnotationGetterOnly), ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2111", nameof (VirtualProperty3WithAnnotationGetterOnly))] static void ReflectionOnPropertyWithGetterOnlyOnVirtual () { typeof (AnnotatedProperty).GetProperty (nameof (VirtualProperty3WithAnnotationGetterOnly)); @@ -453,15 +447,13 @@ namespace Mono.Linker.Tests.Cases.DataFlow typeof (AnnotatedProperty).GetMethod ("get_" + nameof (Property1WithAnnotation)); } - // Intrinsic is disabled https://github.com/dotnet/linker/issues/2559 - [ExpectedWarning ("IL2111", nameof (Property1WithAnnotation) + ".set", ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2111", nameof (Property1WithAnnotation) + ".set")] static void ReflectionOnSetter () { typeof (AnnotatedProperty).GetMethod ("set_" + nameof (Property1WithAnnotation)); } - // Intrinsic is disabled https://github.com/dotnet/linker/issues/2559 - [ExpectedWarning ("IL2111", nameof (VirtualProperty3WithAnnotationGetterOnly) + ".get", ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2111", nameof (VirtualProperty3WithAnnotationGetterOnly) + ".get")] static void ReflectionOnVirtualGetter () { typeof (AnnotatedProperty).GetMethod ("get_" + nameof (VirtualProperty3WithAnnotationGetterOnly)); @@ -662,8 +654,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow var _ = new Action<Type> (GenericWithAnnotatedMethod<TestType>.AnnotatedMethod); } - // Intrinsic is disabled https://github.com/dotnet/linker/issues/2559 - [ExpectedWarning ("IL2111", nameof (GenericMethodWithAnnotation), ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2111", nameof (GenericMethodWithAnnotation))] public static void GenericMethodWithAnnotationReflection () { typeof (AnnotationOnGenerics).GetMethod (nameof (GenericMethodWithAnnotation)); diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/DynamicDependencyDataflow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/DynamicDependencyDataflow.cs index 8237bc4db..029e5848b 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/DynamicDependencyDataflow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/DynamicDependencyDataflow.cs @@ -18,18 +18,16 @@ namespace Mono.Linker.Tests.Cases.DataFlow [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] static Type TypeWithPublicMethods; - // Intrinsic is disabled https://github.com/dotnet/linker/issues/2559 [Kept] - [ExpectedWarning ("IL2080", nameof (Type.GetField), ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2080", nameof (Type.GetField))] [DynamicDependency ("DynamicDependencyTo")] static void DynamicDependencyFrom () { _ = TypeWithPublicMethods.GetField ("f"); } - // Intrinsic is disabled https://github.com/dotnet/linker/issues/2559 [Kept] - [ExpectedWarning ("IL2080", nameof (Type.GetProperty), ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2080", nameof (Type.GetProperty))] static void DynamicDependencyTo () { _ = TypeWithPublicMethods.GetProperty ("p"); |