Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Boemer <sbomer@gmail.com>2022-02-01 03:27:48 +0300
committerSven Boemer <sbomer@gmail.com>2022-02-01 03:27:48 +0300
commit9130ef7d551e0c97b152fe592327108889cb45b0 (patch)
tree6bbd3b7461c04b7bb4fc5abaa8b8cd1cb2ed3a1d /test/Mono.Linker.Tests.Cases
parent3f704bb49eb2fb2847ceaecfbabe8d5f3e0c86c9 (diff)
parentf6fde401e2841726ac04fcc37a34ce402ac800c6 (diff)
Merge remote-tracking branch 'origin/feature/damAnalyzer' into mergeFromMain
Diffstat (limited to 'test/Mono.Linker.Tests.Cases')
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/ApplyTypeAnnotations.cs7
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/AssemblyQualifiedNameDataflow.cs13
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/AttributeConstructorDataflow.cs2
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/AttributeFieldDataflow.cs1
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/AttributePropertyDataflow.cs1
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs9
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs15
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/DynamicDependencyDataflow.cs5
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/EmptyArrayIntrinsicsDataFlow.cs11
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/ExceptionalDataFlow.cs814
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs67
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs275
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/GetNestedTypeOnAllAnnotatedType.cs61
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/GetTypeDataFlow.cs79
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/GetTypeInfoDataFlow.cs39
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/IReflectDataflow.cs1
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/LocalDataFlow.cs259
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/LocalDataFlowKeptMembers.cs1
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/MemberTypes.cs58
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/MemberTypesAllOnCopyAssembly.cs2
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs108
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/MethodReturnParameterDataFlow.cs56
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs82
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs163
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/SuppressWarningWithLinkAttributes.cs7
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/SuppressWarningWithLinkAttributes.xml2
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/TypeBaseTypeDataFlow.cs58
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/TypeInfoAsTypeDataFlow.cs39
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/UnresolvedMembers.cs4
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/VirtualMethodHierarchyDataflowAnnotationValidation.cs4
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/XmlAnnotations.cs91
-rw-r--r--test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.cs43
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/ActivatorCreateInstance.cs34
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithSweptReferences.cs2
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/ConstructorUsedViaReflection.cs34
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/ConstructorsUsedViaReflection.cs9
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs22
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/EventsUsedViaReflection.cs12
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/ExpressionCallString.cs5
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/ExpressionFieldString.cs27
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/ExpressionNewType.cs15
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/ExpressionPropertyMethodInfo.cs13
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/ExpressionPropertyString.cs6
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs22
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/FieldsUsedViaReflection.cs11
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/MemberUsedViaReflection.cs12
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/MembersUsedViaReflection.cs9
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs58
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/MethodsUsedViaReflection.cs10
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/NestedTypeUsedViaReflection.cs22
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/NestedTypesUsedViaReflection.cs10
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/PropertiesUsedViaReflection.cs13
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs43
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/RunClassConstructorUsedViaReflection.cs12
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/RuntimeReflectionExtensionsCalls.cs21
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs20
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeDoesntExist.cs2
-rw-r--r--test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresAttributeMismatch.cs16
-rw-r--r--test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityReflectionAnalysisEnabled.cs6
-rw-r--r--test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs4
-rw-r--r--test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs4
61 files changed, 1708 insertions, 1143 deletions
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/ApplyTypeAnnotations.cs b/test/Mono.Linker.Tests.Cases/DataFlow/ApplyTypeAnnotations.cs
index 5863cf4a4..5770bdfa4 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/ApplyTypeAnnotations.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/ApplyTypeAnnotations.cs
@@ -9,6 +9,7 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions;
namespace Mono.Linker.Tests.Cases.DataFlow
{
+ [ExpectedNoWarnings]
public class ApplyTypeAnnotations
{
public static void Main ()
@@ -50,6 +51,12 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
[Kept]
+ // Analyzer doesn't support intrinsics: https://github.com/dotnet/linker/issues/2374
+ [ExpectedWarning ("IL2026", "System.Type.GetType(String)",
+ ProducedBy = ProducedBy.Analyzer)]
+ // Analyzer doesn't track known types: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2072", "'type'", nameof (ApplyTypeAnnotations) + "." + nameof (RequireCombination) + "(Type)", "System.Type.GetType(String)",
+ ProducedBy = ProducedBy.Analyzer)]
static void TestFromTypeGetTypeOverConstant ()
{
RequireCombination (Type.GetType ("Mono.Linker.Tests.Cases.DataFlow.ApplyTypeAnnotations+FromTypeGetTypeOverConstantTestType"));
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/AssemblyQualifiedNameDataflow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/AssemblyQualifiedNameDataflow.cs
index 8761da610..4a478e2a6 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/AssemblyQualifiedNameDataflow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/AssemblyQualifiedNameDataflow.cs
@@ -7,8 +7,9 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions;
namespace Mono.Linker.Tests.Cases.DataFlow
{
// Note: this test's goal is to validate that the product correctly reports unrecognized patterns
- // - so the main validation is done by the UnrecognizedReflectionAccessPattern attributes.
+ // - so the main validation is done by the ExpectedWarning attributes.
[SkipKeptItemsValidation]
+ [ExpectedNoWarnings]
class AssemblyQualifiedNameDataflow
{
static void Main ()
@@ -19,8 +20,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
TestUnqualifiedTypeNameWarns ();
}
- [UnrecognizedReflectionAccessPattern (typeof (AssemblyQualifiedNameDataflow), nameof (RequirePublicConstructors), new Type[] { typeof (string) }, messageCode: "IL2072")]
- [UnrecognizedReflectionAccessPattern (typeof (AssemblyQualifiedNameDataflow), nameof (RequireNonPublicConstructors), new Type[] { typeof (string) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (RequirePublicConstructors))]
+ [ExpectedWarning ("IL2072", nameof (RequireNonPublicConstructors))]
static void TestPublicParameterlessConstructor ()
{
string type = GetTypeWithPublicParameterlessConstructor ().AssemblyQualifiedName;
@@ -30,7 +31,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
RequireNothing (type);
}
- [UnrecognizedReflectionAccessPattern (typeof (AssemblyQualifiedNameDataflow), nameof (RequireNonPublicConstructors), new Type[] { typeof (string) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (RequireNonPublicConstructors))]
static void TestPublicConstructors ()
{
string type = GetTypeWithPublicConstructors ().AssemblyQualifiedName;
@@ -40,8 +41,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
RequireNothing (type);
}
- [UnrecognizedReflectionAccessPattern (typeof (AssemblyQualifiedNameDataflow), nameof (RequirePublicParameterlessConstructor), new Type[] { typeof (string) }, messageCode: "IL2072")]
- [UnrecognizedReflectionAccessPattern (typeof (AssemblyQualifiedNameDataflow), nameof (RequirePublicConstructors), new Type[] { typeof (string) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (RequirePublicParameterlessConstructor))]
+ [ExpectedWarning ("IL2072", nameof (RequirePublicConstructors))]
static void TestConstructors ()
{
string type = GetTypeWithNonPublicConstructors ().AssemblyQualifiedName;
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/AttributeConstructorDataflow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/AttributeConstructorDataflow.cs
index 3b5aff228..76e31e833 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/AttributeConstructorDataflow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/AttributeConstructorDataflow.cs
@@ -11,6 +11,7 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions;
namespace Mono.Linker.Tests.Cases.DataFlow
{
[Kept]
+ [ExpectedNoWarnings]
class AttributeConstructorDataflow
{
[KeptAttributeAttribute (typeof (KeepsPublicConstructorAttribute))]
@@ -73,7 +74,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
class AllOnSelf
{
[Kept]
- [RecognizedReflectionAccessPattern]
public static void Test ()
{
var t = typeof (KeepAllOnSelf);
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/AttributeFieldDataflow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/AttributeFieldDataflow.cs
index 7da1ed05b..75b619a21 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/AttributeFieldDataflow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/AttributeFieldDataflow.cs
@@ -11,6 +11,7 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions;
namespace Mono.Linker.Tests.Cases.DataFlow
{
[Kept]
+ [ExpectedNoWarnings]
class AttributeFieldDataflow
{
[KeptAttributeAttribute (typeof (KeepsPublicConstructorsAttribute))]
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/AttributePropertyDataflow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/AttributePropertyDataflow.cs
index 8c4dac3b2..4f1e84123 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/AttributePropertyDataflow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/AttributePropertyDataflow.cs
@@ -11,6 +11,7 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions;
namespace Mono.Linker.Tests.Cases.DataFlow
{
[Kept]
+ [ExpectedNoWarnings]
class AttributePropertyDataflow
{
[KeptAttributeAttribute (typeof (KeepsPublicConstructorsAttribute))]
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs
index 6cb0409cf..6b088291e 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs
@@ -12,6 +12,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
[SetupCompileArgument ("/langversion:7.3")]
[Kept]
+ [ExpectedNoWarnings]
class ByRefDataflow
{
public static void Main ()
@@ -40,14 +41,18 @@ namespace Mono.Linker.Tests.Cases.DataFlow
static Type s_typeWithPublicParameterlessConstructor;
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (ByRefDataflow), nameof (MethodWithRefParameter), new string[] { "Type&" }, messageCode: "IL2077")]
+ // Trimmer and analyzer use different formats for ref parameters: https://github.com/dotnet/linker/issues/2406
+ [ExpectedWarning ("IL2077", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(Type&)", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2077", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(ref Type)", ProducedBy = ProducedBy.Analyzer)]
public static void PassRefToField ()
{
MethodWithRefParameter (ref s_typeWithPublicParameterlessConstructor);
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (ByRefDataflow), nameof (MethodWithRefParameter), new string[] { "Type&" }, messageCode: "IL2067")]
+ // Trimmer and analyzer use different formats for ref parameters: https://github.com/dotnet/linker/issues/2406
+ [ExpectedWarning ("IL2067", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(Type&)", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2067", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(ref Type)", ProducedBy = ProducedBy.Analyzer)]
public static void PassRefToParameter (Type parameter)
{
MethodWithRefParameter (ref parameter);
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs b/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs
index 7bcfbc70c..858d40088 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs
@@ -99,6 +99,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
[Kept]
+ // Analyzer doesn't support intrinsics: https://github.com/dotnet/linker/issues/2374
+ [ExpectedWarning ("IL2072", "'type'", nameof (ComplexTypeHandling) + "." + nameof (RequirePublicMethods) + "(Type)", "System.Object.GetType()",
+ ProducedBy = ProducedBy.Analyzer)]
static void TestArrayGetTypeFromMethodParamHelper (ArrayGetTypeFromMethodParamElement[] p)
{
RequirePublicMethods (p.GetType ());
@@ -121,6 +124,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow
static ArrayGetTypeFromFieldElement[] _arrayGetTypeFromField;
[Kept]
+ // Analyzer doesn't support intrinsics: https://github.com/dotnet/linker/issues/2374
+ [ExpectedWarning ("IL2072", "'type'", nameof (ComplexTypeHandling) + "." + nameof (RequirePublicMethods) + "(Type)", "System.Object.GetType()",
+ ProducedBy = ProducedBy.Analyzer)]
static void TestArrayGetTypeFromField ()
{
RequirePublicMethods (_arrayGetTypeFromField.GetType ());
@@ -134,6 +140,12 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
[Kept]
+ // Analyzer doesn't support intrinsics: https://github.com/dotnet/linker/issues/2374
+ [ExpectedWarning ("IL2026", "System.Type.GetType(String)",
+ ProducedBy = ProducedBy.Analyzer)]
+ // Analyzer doesn't track known types: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2072", "'type'", nameof (ComplexTypeHandling) + "." + nameof (RequirePublicMethods) + "(Type)", "System.Type.GetType(String)",
+ ProducedBy = ProducedBy.Analyzer)]
static void TestArrayTypeGetType ()
{
RequirePublicMethods (Type.GetType ("Mono.Linker.Tests.Cases.DataFlow.ComplexTypeHandling+ArrayTypeGetTypeElement[]"));
@@ -148,6 +160,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
[Kept]
+ // Analyzer doesn't support intrinsics: https://github.com/dotnet/linker/issues/2374
+ [ExpectedWarning ("IL2026", "Activator.CreateInstance(String, String)",
+ ProducedBy = ProducedBy.Analyzer)]
static void TestArrayCreateInstanceByName ()
{
Activator.CreateInstance ("test", "Mono.Linker.Tests.Cases.DataFlow.ComplexTypeHandling+ArrayCreateInstanceByNameElement[]");
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/DynamicDependencyDataflow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/DynamicDependencyDataflow.cs
index 1fe9a13be..029e5848b 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/DynamicDependencyDataflow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/DynamicDependencyDataflow.cs
@@ -5,6 +5,7 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions;
namespace Mono.Linker.Tests.Cases.DataFlow
{
+ [ExpectedNoWarnings]
public class DynamicDependencyDataflow
{
public static void Main ()
@@ -18,7 +19,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
static Type TypeWithPublicMethods;
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Type), "GetField", new Type[] { typeof (string) }, messageCode: "IL2080")]
+ [ExpectedWarning ("IL2080", nameof (Type.GetField))]
[DynamicDependency ("DynamicDependencyTo")]
static void DynamicDependencyFrom ()
{
@@ -26,7 +27,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Type), "GetProperty", new Type[] { typeof (string) }, messageCode: "IL2080")]
+ [ExpectedWarning ("IL2080", nameof (Type.GetProperty))]
static void DynamicDependencyTo ()
{
_ = TypeWithPublicMethods.GetProperty ("p");
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/EmptyArrayIntrinsicsDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/EmptyArrayIntrinsicsDataFlow.cs
index 34e524215..2e89e0c7e 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/EmptyArrayIntrinsicsDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/EmptyArrayIntrinsicsDataFlow.cs
@@ -8,8 +8,9 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions;
namespace Mono.Linker.Tests.Cases.DataFlow
{
// Note: this test's goal is to validate that the product correctly reports unrecognized patterns
- // - so the main validation is done by the UnrecognizedReflectionAccessPattern attributes.
+ // - so the main validation is done by the ExpectedWarning attributes.
[SkipKeptItemsValidation]
+ [ExpectedNoWarnings]
class EmptyArrayIntrinsicsDataFlow
{
static void Main ()
@@ -20,27 +21,27 @@ namespace Mono.Linker.Tests.Cases.DataFlow
TestGetConstructorOverloads ();
}
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string) }, messageCode: "IL2080")]
+ [ExpectedWarning ("IL2080", nameof (Type.GetMethod))]
static void TestGetPublicParameterlessConstructorWithEmptyTypes ()
{
s_typeWithKeptPublicParameterlessConstructor.GetConstructor (Type.EmptyTypes);
s_typeWithKeptPublicParameterlessConstructor.GetMethod ("Foo");
}
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string) }, messageCode: "IL2080")]
+ [ExpectedWarning ("IL2080", nameof (Type.GetMethod))]
static void TestGetPublicParameterlessConstructorWithArrayEmpty ()
{
s_typeWithKeptPublicParameterlessConstructor.GetConstructor (Array.Empty<Type> ());
s_typeWithKeptPublicParameterlessConstructor.GetMethod ("Foo");
}
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (Type[]) }, messageCode: "IL2080")]
+ [ExpectedWarning ("IL2080", nameof (Type.GetConstructor))]
static void TestGetPublicParameterlessConstructorWithUnknownArray ()
{
s_typeWithKeptPublicParameterlessConstructor.GetConstructor (s_localEmptyArrayInvisibleToAnalysis);
}
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string) }, messageCode: "IL2080")]
+ [ExpectedWarning ("IL2080", nameof (Type.GetMethod))]
static void TestGetConstructorOverloads ()
{
s_typeWithKeptPublicParameterlessConstructor.GetConstructor (BindingFlags.Public, null, Type.EmptyTypes, null);
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/ExceptionalDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/ExceptionalDataFlow.cs
new file mode 100644
index 000000000..40bf18ca7
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/ExceptionalDataFlow.cs
@@ -0,0 +1,814 @@
+using System;
+using System.Diagnostics.CodeAnalysis;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+
+namespace Mono.Linker.Tests.Cases.DataFlow
+{
+ [SkipKeptItemsValidation]
+ public class ExceptionalDataFlow
+ {
+ public static void Main ()
+ {
+ TryFlowsToFinally ();
+ TryFlowsToAfterFinally ();
+ MultipleTryExits ();
+ MultipleFinallyPaths ();
+ FinallyChain ();
+ FinallyChainWithPostFinallyState ();
+ TryFlowsToCatch ();
+ CatchFlowsToFinally ();
+ CatchFlowsToAfterTry ();
+ CatchFlowsToAfterFinally ();
+ FinallyFlowsToAfterFinally ();
+ TryFlowsToMultipleCatchAndFinally ();
+ NestedWithFinally ();
+ ControlFlowsOutOfMultipleFinally ();
+ NestedWithCatch ();
+ CatchInTry ();
+ CatchInTryWithFinally ();
+ TestCatchesHaveSeparateState ();
+ FinallyWithBranchToFirstBlock ();
+ FinallyWithBranchToFirstBlockAndEnclosingTryCatchState ();
+ CatchWithBranchToFirstBlock ();
+ CatchWithBranchToFirstBlockAndReassignment ();
+ CatchWithNonSimplePredecessor ();
+ FinallyWithNonSimplePredecessor ();
+ FinallyInTryWithPredecessor ();
+ NestedFinally ();
+ NestedFinallyWithPredecessor ();
+ }
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+ public static void TryFlowsToFinally ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ t = GetWithPublicFields ();
+ t = GetWithPublicProperties ();
+ } finally {
+ // methods/fields/properties
+ RequireAll (t);
+ }
+ }
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+ public static void TryFlowsToAfterFinally ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ t = GetWithPublicFields ();
+ t = GetWithPublicProperties ();
+ } finally {
+ // prevent optimizing this away
+ _ = string.Empty;
+ }
+ // properties
+ RequireAll (t);
+ }
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicConstructors) + "()")]
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods) + "()")]
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields) + "()")]
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+ public static void MultipleTryExits ()
+ {
+ Type t = GetWithPublicConstructors ();
+ for (int i = 0; i < 10; i++) {
+ try {
+ if (string.Empty.Length == 0) {
+ t = GetWithPublicMethods ();
+ return;
+ }
+ if (string.Empty.Length == 1) {
+ t = GetWithPublicFields ();
+ continue;
+ }
+ if (string.Empty.Length == 2) {
+ t = GetWithPublicProperties ();
+ break;
+ }
+ } finally {
+ RequireAll (t);
+ }
+ }
+ }
+
+ // There are multiple paths through the finally to different subsequent blocks.
+ // On each path, only one state is possible, but we conservatively merge the (non-exceptional)
+ // finally states for each path and expect the warnings to reflect this merged state.
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicMethods) + "()")]
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicProperties) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicEvents) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicMethods) + "()")]
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields) + "()")]
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicEvents) + "()")]
+
+ [ExpectedWarning ("IL2073", nameof (MultipleFinallyPaths) + "()", nameof (GetWithPublicEvents) + "()")]
+ [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)]
+ public static Type MultipleFinallyPaths ()
+ {
+ Type t = GetWithPublicMethods (); // reaches RequireAll1 and RequireAll2
+ while (true) {
+ RequireAll1 (t);
+ try {
+ if (string.Empty.Length == 1) {
+ t = GetWithPublicFields (); // reaches RequireAll1 and RequireAll2
+ continue;
+ }
+ if (string.Empty.Length == 0) {
+ t = GetWithPublicProperties (); // reaches RequireAll2 only, but the finally mergig means
+ // the analysis thinks it can reach RequireAll1.
+ break;
+ }
+ if (string.Empty.Length == 2) {
+ t = GetWithPublicEvents (); // reaches return only, but the finally merging means
+ // the analysis thinks it can reach RequireAll1 (and hence RequireAll2).
+ return t;
+ }
+ } finally {
+ _ = string.Empty;
+ }
+ }
+ RequireAll2 (t); // properties
+
+ throw new Exception ();
+ }
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+ public static void FinallyChain ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ t = GetWithPublicFields ();
+ try {
+ t = GetWithPublicProperties ();
+ } finally {
+ RequireAll1 (t); // fields/properties
+ }
+ } finally {
+ RequireAll2 (t); // methods/fields/properties
+ }
+ }
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll4) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+ public static void FinallyChainWithPostFinallyState ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ t = GetWithPublicFields ();
+ try {
+ t = GetWithPublicProperties ();
+ } finally {
+ // normal: properties
+ // exception: fields/properties
+ RequireAll1 (t); // fields/properties
+ }
+ RequireAll2 (t); // properties
+ } finally {
+ // normal: properties
+ // exception: methods/fields/properties
+ RequireAll3 (t); // methods/fields/properties
+ }
+ RequireAll4 (t);
+ }
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+ public static void TryFlowsToCatch ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ t = GetWithPublicFields ();
+ t = GetWithPublicProperties ();
+ } catch {
+ // methods/fields/properties
+ RequireAll (t);
+ }
+ }
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+ public static void CatchFlowsToFinally ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ } catch {
+ t = GetWithPublicFields ();
+ t = GetWithPublicProperties ();
+ } finally {
+ // methods/fields/properties
+ RequireAll (t);
+ }
+ }
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+ public static void CatchFlowsToAfterTry ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ } catch {
+ t = GetWithPublicFields ();
+ t = GetWithPublicProperties ();
+ }
+ // methods/properties, not fields
+ RequireAll (t);
+ }
+
+
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+ public static void CatchFlowsToAfterFinally ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ } catch {
+ t = GetWithPublicFields ();
+ t = GetWithPublicProperties ();
+ } finally { }
+ // methods/properties, not fields
+ RequireAll (t);
+ }
+
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+ public static void FinallyFlowsToAfterFinally ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ } finally {
+ t = GetWithPublicFields ();
+ t = GetWithPublicProperties ();
+ }
+ // properties only
+ RequireAll (t);
+ }
+
+ public class Exception1 : Exception { }
+ public class Exception2 : Exception { }
+
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicFields) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll4) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll4) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll5) + "(Type)", nameof (GetWithPublicEvents) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll6) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll6) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll6) + "(Type)", nameof (GetWithPublicProperties) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll6) + "(Type)", nameof (GetWithPublicEvents) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll7) + "(Type)", nameof (GetWithPublicConstructors) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicConstructors) + "()")]
+
+
+ public static void TryFlowsToMultipleCatchAndFinally ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ t = GetWithPublicFields ();
+ RequireAll1 (t); // fields only
+ } catch (Exception1) {
+ RequireAll2 (t); // methods/fields
+ t = GetWithPublicProperties ();
+ RequireAll3 (t); // properties only
+ } catch (Exception2) {
+ RequireAll4 (t); // methods/fields
+ t = GetWithPublicEvents ();
+ RequireAll5 (t); // events only
+ } finally {
+ RequireAll6 (t); // methods/fields/properties/events
+ t = GetWithPublicConstructors ();
+ RequireAll7 (t); // ctors only
+ }
+ RequireAll (t);
+ }
+
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicConstructors) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicProperties) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicEvents) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicConstructors) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+
+ public static void NestedWithFinally ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ t = GetWithPublicFields ();
+ try {
+ // fields
+ t = GetWithPublicProperties ();
+ } finally {
+ // fields/properties
+ RequireAll1 (t);
+ t = GetWithPublicEvents ();
+ t = GetWithPublicConstructors ();
+ }
+ // ctors
+ RequireAll2 (t);
+ } finally {
+ // methods/fields/properties/events/constructors
+ RequireAll3 (t);
+ }
+ }
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicFields) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicProperties) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicEvents) + "()")]
+ public static void ControlFlowsOutOfMultipleFinally ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ try {
+ try {
+ t = GetWithPublicFields ();
+ } finally {
+ // methods/fields
+ RequireAll1 (t);
+ t = GetWithPublicProperties ();
+ }
+ } finally {
+ // methods/fields/properties
+ RequireAll2 (t);
+ t = GetWithPublicEvents ();
+ }
+ } finally {
+ // methods/fields/propreties/events
+ RequireAll3 (t);
+ }
+ }
+
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicProperties) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicConstructors) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicProperties) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicEvents) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicConstructors) + "()")]
+
+ public static void NestedWithCatch ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ t = GetWithPublicFields ();
+ try {
+ // fields
+ t = GetWithPublicProperties ();
+ } catch {
+ // fields/properties
+ RequireAll1 (t);
+ t = GetWithPublicEvents ();
+ t = GetWithPublicConstructors ();
+ }
+ // properties/ctors
+ RequireAll2 (t);
+ } catch {
+ // methods/fields/properties/events/constructors
+ RequireAll3 (t);
+ }
+ }
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields) + "()")]
+ public static void CatchInTry ()
+ {
+ try {
+ Type t = GetWithPublicMethods ();
+ try {
+ } catch {
+ t = GetWithPublicFields ();
+ RequireAll (t);
+ }
+ } catch {
+ }
+ }
+
+ // This tests a case where the catch state was being merged with the containing try state incorrectly.
+ // In the bug, the exceptional catch state, which is used in the finally, had too much in it.
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicFields) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicMethods) + "()")]
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields) + "()")]
+ // The bug was producing this warning:
+ // [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicConstructors) + "()")]
+ public static void CatchInTryWithFinally ()
+ {
+ Type t = GetWithPublicConstructors ();
+ try {
+ t = GetWithPublicMethods ();
+ // methods
+ // ex: ctors/methods
+ try {
+ // methods
+ // ex: methods
+ } catch {
+ // methods
+ t = GetWithPublicFields ();
+ // fields
+ // ex: methods/fields
+ RequireAll1 (t);
+ } finally {
+ // normal state: fields
+ // exceptional state: methods/fields
+ RequireAll2 (t);
+ }
+ } catch {
+ }
+ }
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods) + "()")]
+
+ public static void TestCatchesHaveSeparateState ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ } catch (Exception1) {
+ t = GetWithPublicFields ();
+ } catch (Exception2) {
+ // methods only!
+ RequireAll (t);
+ } finally {
+ }
+ }
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods) + "()")]
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ public static void FinallyWithBranchToFirstBlock ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ } finally {
+ FinallyStart:
+ RequireAll (t);
+ t = GetWithPublicFields ();
+ goto FinallyStart;
+ }
+ }
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods) + "()")]
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ public static void FinallyWithBranchToFirstBlockAndEnclosingTryCatchState ()
+ {
+ try {
+ Type t = GetWithPublicProperties ();
+ t = GetWithPublicMethods ();
+ try {
+ } finally {
+ FinallyStart:
+ // methods/fields
+ RequireAll (t);
+ t = GetWithPublicFields ();
+ goto FinallyStart;
+ }
+ } finally {
+ // An operation just to prevent optimizing away
+ // the try/finally.
+ _ = String.Empty;
+ }
+ }
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods) + "()")]
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ public static void CatchWithBranchToFirstBlock ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ } catch {
+ CatchStart:
+ RequireAll (t);
+ t = GetWithPublicFields ();
+ goto CatchStart;
+ }
+ }
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods) + "()")]
+ [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ public static void CatchWithBranchToFirstBlockAndReassignment ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ } catch {
+ CatchStart:
+ RequireAll (t); // methods/fields, but not properties!
+ t = GetWithPublicProperties ();
+ t = GetWithPublicFields ();
+ goto CatchStart;
+ }
+ }
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+ public static void CatchWithNonSimplePredecessor ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ t = GetWithPublicFields ();
+ t = GetWithPublicProperties ();
+ try {
+ // properties only
+ } catch {
+ // properties only.
+ RequireAll1 (t);
+ }
+ } catch {
+ // methods/fields/properties
+ RequireAll2 (t);
+ }
+ }
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+ public static void FinallyWithNonSimplePredecessor ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ t = GetWithPublicFields ();
+ t = GetWithPublicProperties ();
+ try {
+ // properties only
+ } catch {
+ // properties only.
+ RequireAll1 (t);
+ }
+ } finally {
+ // methods/fields/properties
+ RequireAll2 (t);
+ }
+ }
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+ public static void FinallyInTryWithPredecessor ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ t = GetWithPublicFields ();
+ t = GetWithPublicProperties ();
+ try {
+ // properties only
+ } finally {
+ // properties only.
+ RequireAll1 (t);
+ }
+ } finally {
+ // methods/fields/properties
+ RequireAll2 (t);
+ }
+ }
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicFields) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+ public static void NestedFinally ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ t = GetWithPublicFields ();
+ } finally {
+ try {
+ RequireAll1 (t);
+ t = GetWithPublicProperties ();
+ } finally {
+ RequireAll2 (t);
+ }
+ RequireAll3 (t);
+ }
+ }
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicFields) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+
+ [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicProperties) + "()")]
+ public static void NestedFinallyWithPredecessor ()
+ {
+ Type t = GetWithPublicMethods ();
+ try {
+ t = GetWithPublicFields ();
+ } finally {
+ _ = 0; // add an operation so that the try isn't the start of the finally.
+ try {
+ RequireAll1 (t);
+ t = GetWithPublicProperties ();
+ } finally {
+ RequireAll2 (t);
+ }
+ RequireAll3 (t);
+ }
+ }
+
+ [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
+ public static Type GetWithPublicMethods ()
+ {
+ return null;
+ }
+
+ [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)]
+ public static Type GetWithPublicFields ()
+ {
+ return null;
+ }
+ [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicProperties)]
+ public static Type GetWithPublicProperties ()
+ {
+ return null;
+ }
+ [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicEvents)]
+ public static Type GetWithPublicEvents ()
+ {
+ return null;
+ }
+ [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
+ public static Type GetWithPublicConstructors ()
+ {
+ return null;
+ }
+
+ public static void RequirePublicMethods (
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
+ Type type)
+ {
+ }
+
+ public static void RequirePublicFields (
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)]
+ Type type)
+ {
+ }
+ public static void RequirePublicProperties (
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)]
+ Type type)
+ {
+ }
+
+
+ public static void RequireFieldsAndProperties (
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicProperties)]
+ Type type)
+ {
+ }
+
+ public static void RequireAll (
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
+ Type type)
+ {
+ }
+ public static void RequireAll1 (
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
+ Type type)
+ {
+ }
+ public static void RequireAll2 (
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
+ Type type)
+ {
+ }
+ public static void RequireAll3 (
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
+ Type type)
+ {
+ }
+ public static void RequireAll4 (
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
+ Type type)
+ {
+ }
+ public static void RequireAll5 (
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
+ Type type)
+ {
+ }
+ public static void RequireAll6 (
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
+ Type type)
+ {
+ }
+ public static void RequireAll7 (
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
+ Type type)
+ {
+ }
+ }
+} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs
index cb36d87a3..51d21f1f2 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
@@ -10,8 +10,9 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions;
namespace Mono.Linker.Tests.Cases.DataFlow
{
// Note: this test's goal is to validate that the product correctly reports unrecognized patterns
- // - so the main validation is done by the UnrecognizedReflectionAccessPattern attributes.
+ // - so the main validation is done by the ExpectedWarning attributes.
[SkipKeptItemsValidation]
+ [ExpectedNoWarnings]
public class FieldDataFlow
{
public static void Main ()
@@ -43,13 +44,15 @@ namespace Mono.Linker.Tests.Cases.DataFlow
static Type _staticTypeWithoutRequirements;
- [ExpectedWarning ("IL2097", nameof (_annotationOnWrongType))]
+ // TODO: warn about annotation on wrong type in analyzer: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2097", nameof (_annotationOnWrongType),
+ ProducedBy = ProducedBy.Trimmer)]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)]
static object _annotationOnWrongType;
- [UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) },
- messageCode: "IL2077", message: new string[] { "_typeWithPublicParameterlessConstructor", "type", "RequirePublicConstructors(Type)" })]
- [UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (RequireNonPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2077")]
+ [ExpectedWarning ("IL2077", nameof (RequirePublicConstructors),
+ "_typeWithPublicParameterlessConstructor", "type", "RequirePublicConstructors(Type)")]
+ [ExpectedWarning ("IL2077", nameof (RequireNonPublicConstructors))]
private void ReadFromInstanceField ()
{
RequirePublicParameterlessConstructor (_typeWithPublicParameterlessConstructor);
@@ -58,22 +61,18 @@ namespace Mono.Linker.Tests.Cases.DataFlow
RequireNothing (_typeWithPublicParameterlessConstructor);
}
- [UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (_typeWithPublicParameterlessConstructor),
- messageCode: "IL2074", message: new string[] {
- nameof (GetUnkownType),
- nameof (_typeWithPublicParameterlessConstructor)
- })]
- [UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (_typeWithPublicParameterlessConstructor), messageCode: "IL2074")]
+ [ExpectedWarning ("IL2074", nameof (FieldDataFlow) + "." + nameof (_typeWithPublicParameterlessConstructor), nameof (GetUnknownType))]
+ [ExpectedWarning ("IL2074", nameof (FieldDataFlow) + "." + nameof (_typeWithPublicParameterlessConstructor), nameof (GetTypeWithNonPublicConstructors))]
private void WriteToInstanceField ()
{
_typeWithPublicParameterlessConstructor = GetTypeWithPublicParameterlessConstructor ();
_typeWithPublicParameterlessConstructor = GetTypeWithPublicConstructors ();
_typeWithPublicParameterlessConstructor = GetTypeWithNonPublicConstructors ();
- _typeWithPublicParameterlessConstructor = GetUnkownType ();
+ _typeWithPublicParameterlessConstructor = GetUnknownType ();
}
- [UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2077")]
- [UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (RequireNonPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2077")]
+ [ExpectedWarning ("IL2077", nameof (RequirePublicConstructors))]
+ [ExpectedWarning ("IL2077", nameof (RequireNonPublicConstructors))]
private void ReadFromInstanceFieldOnADifferentClass ()
{
var store = new TypeStore ();
@@ -84,8 +83,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
RequireNothing (store._typeWithPublicParameterlessConstructor);
}
- [UnrecognizedReflectionAccessPattern (typeof (TypeStore), nameof (TypeStore._typeWithPublicParameterlessConstructor), messageCode: "IL2074")]
- [UnrecognizedReflectionAccessPattern (typeof (TypeStore), nameof (TypeStore._typeWithPublicParameterlessConstructor), messageCode: "IL2074")]
+ [ExpectedWarning ("IL2074", nameof (TypeStore) + "." + nameof (TypeStore._typeWithPublicParameterlessConstructor), nameof (GetUnknownType))]
+ [ExpectedWarning ("IL2074", nameof (TypeStore) + "." + nameof (TypeStore._typeWithPublicParameterlessConstructor), nameof (GetTypeWithNonPublicConstructors))]
private void WriteToInstanceFieldOnADifferentClass ()
{
var store = new TypeStore ();
@@ -93,11 +92,11 @@ namespace Mono.Linker.Tests.Cases.DataFlow
store._typeWithPublicParameterlessConstructor = GetTypeWithPublicParameterlessConstructor ();
store._typeWithPublicParameterlessConstructor = GetTypeWithPublicConstructors ();
store._typeWithPublicParameterlessConstructor = GetTypeWithNonPublicConstructors ();
- store._typeWithPublicParameterlessConstructor = GetUnkownType ();
+ store._typeWithPublicParameterlessConstructor = GetUnknownType ();
}
- [UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2077")]
- [UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (RequireNonPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2077")]
+ [ExpectedWarning ("IL2077", nameof (RequirePublicConstructors))]
+ [ExpectedWarning ("IL2077", nameof (RequireNonPublicConstructors))]
private void ReadFromStaticField ()
{
RequirePublicParameterlessConstructor (_staticTypeWithPublicParameterlessConstructor);
@@ -106,24 +105,20 @@ namespace Mono.Linker.Tests.Cases.DataFlow
RequireNothing (_staticTypeWithPublicParameterlessConstructor);
}
- [UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (_staticTypeWithPublicParameterlessConstructor), messageCode: "IL2074")]
- [UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (_staticTypeWithPublicParameterlessConstructor), messageCode: "IL2074")]
- [UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (_staticTypeWithPublicParameterlessConstructor),
- messageCode: "IL2079", message: new string[] {
- nameof(_staticTypeWithoutRequirements),
- nameof(_staticTypeWithPublicParameterlessConstructor)
- })]
+ [ExpectedWarning ("IL2074", nameof (FieldDataFlow) + "." + nameof (_staticTypeWithPublicParameterlessConstructor), nameof (GetUnknownType))]
+ [ExpectedWarning ("IL2074", nameof (FieldDataFlow) + "." + nameof (_staticTypeWithPublicParameterlessConstructor), nameof (GetTypeWithNonPublicConstructors))]
+ [ExpectedWarning ("IL2079", nameof (FieldDataFlow) + "." + nameof (_staticTypeWithPublicParameterlessConstructor), nameof (_staticTypeWithoutRequirements))]
private void WriteToStaticField ()
{
_staticTypeWithPublicParameterlessConstructor = GetTypeWithPublicParameterlessConstructor ();
_staticTypeWithPublicParameterlessConstructor = GetTypeWithPublicConstructors ();
_staticTypeWithPublicParameterlessConstructor = GetTypeWithNonPublicConstructors ();
- _staticTypeWithPublicParameterlessConstructor = GetUnkownType ();
+ _staticTypeWithPublicParameterlessConstructor = GetUnknownType ();
_staticTypeWithPublicParameterlessConstructor = _staticTypeWithoutRequirements;
}
- [UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2077")]
- [UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (RequireNonPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2077")]
+ [ExpectedWarning ("IL2077", nameof (RequirePublicConstructors))]
+ [ExpectedWarning ("IL2077", nameof (RequireNonPublicConstructors))]
private void ReadFromStaticFieldOnADifferentClass ()
{
RequirePublicParameterlessConstructor (TypeStore._staticTypeWithPublicParameterlessConstructor);
@@ -132,17 +127,19 @@ namespace Mono.Linker.Tests.Cases.DataFlow
RequireNothing (TypeStore._staticTypeWithPublicParameterlessConstructor);
}
- [UnrecognizedReflectionAccessPattern (typeof (TypeStore), nameof (TypeStore._staticTypeWithPublicParameterlessConstructor), messageCode: "IL2074")]
- [UnrecognizedReflectionAccessPattern (typeof (TypeStore), nameof (TypeStore._staticTypeWithPublicParameterlessConstructor), messageCode: "IL2074")]
+ [ExpectedWarning ("IL2074", nameof (TypeStore) + "." + nameof (TypeStore._staticTypeWithPublicParameterlessConstructor), nameof (GetUnknownType))]
+ [ExpectedWarning ("IL2074", nameof (TypeStore) + "." + nameof (TypeStore._staticTypeWithPublicParameterlessConstructor), nameof (GetTypeWithNonPublicConstructors))]
private void WriteToStaticFieldOnADifferentClass ()
{
TypeStore._staticTypeWithPublicParameterlessConstructor = GetTypeWithPublicParameterlessConstructor ();
TypeStore._staticTypeWithPublicParameterlessConstructor = GetTypeWithPublicConstructors ();
TypeStore._staticTypeWithPublicParameterlessConstructor = GetTypeWithNonPublicConstructors ();
- TypeStore._staticTypeWithPublicParameterlessConstructor = GetUnkownType ();
+ TypeStore._staticTypeWithPublicParameterlessConstructor = GetUnknownType ();
}
- [UnrecognizedReflectionAccessPattern (typeof (TypeStore), nameof (TypeStore._staticTypeWithPublicParameterlessConstructor), messageCode: "IL2064", message: new string[] { nameof (TypeStore._staticTypeWithPublicParameterlessConstructor) })]
+ // TODO: warn about unknown types in analyzer: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2064", nameof (TypeStore) + "." + nameof (TypeStore._staticTypeWithPublicParameterlessConstructor),
+ ProducedBy = ProducedBy.Trimmer)]
private void WriteUnknownValue ()
{
var array = new object[1];
@@ -191,7 +188,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
return null;
}
- private static Type GetUnkownType ()
+ private static Type GetUnknownType ()
{
return null;
}
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs
index 979275897..1b22b25f5 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs
@@ -71,12 +71,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
class TypeRequiresPublicFields<
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] T>
{
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) },
- messageCode: "IL2087", message: new string[] {
- nameof (T),
- nameof (TypeRequiresPublicFields <T>),
- nameof (DataFlowTypeExtensions.RequiresPublicMethods)
- })]
+ [ExpectedWarning ("IL2087", "'" + nameof (T) + "'", nameof (TypeRequiresPublicFields<T>), nameof (DataFlowTypeExtensions.RequiresPublicMethods))]
public static void Test ()
{
typeof (T).RequiresPublicFields ();
@@ -90,12 +85,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (T).RequiresPublicMethods ();
}
- [UnrecognizedReflectionAccessPattern (typeof (GenericParameterDataFlow), nameof (FieldRequiresPublicMethods),
- messageCode: "IL2089", message: new string[] {
- nameof (T),
- nameof (TypeRequiresPublicFields <T>),
- nameof (FieldRequiresPublicMethods)
- })]
+ [ExpectedWarning ("IL2089", "'" + nameof (T) + "'", nameof (TypeRequiresPublicFields<T>), nameof (FieldRequiresPublicMethods))]
public static void TestFields ()
{
FieldRequiresPublicFields = typeof (T);
@@ -104,7 +94,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
- [RecognizedReflectionAccessPattern]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)]
public static Type ReturnRequiresPublicFields ()
{
@@ -112,12 +101,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
- [UnrecognizedReflectionAccessPattern (typeof (TypeRequiresPublicFields<>), nameof (ReturnRequiresPublicMethods), new Type[] { }, returnType: typeof (Type),
- messageCode: "IL2088", message: new string[] {
- nameof (T),
- nameof (TypeRequiresPublicFields<T>),
- nameof (ReturnRequiresPublicMethods)
- })]
+ [ExpectedWarning ("IL2088", "'" + nameof (T) + "'", nameof (TypeRequiresPublicFields<T>), nameof (ReturnRequiresPublicMethods))]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
public static Type ReturnRequiresPublicMethods ()
{
@@ -133,7 +117,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
class TypeRequiresPublicMethods<
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] T>
{
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicFields), new Type[] { typeof (Type) }, messageCode: "IL2087")]
+ [ExpectedWarning ("IL2087", nameof (DataFlowTypeExtensions.RequiresPublicFields))]
public static void Test ()
{
typeof (T).RequiresPublicFields ();
@@ -144,8 +128,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
class TypeRequiresNothing<T>
{
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicFields), new Type[] { typeof (Type) }, messageCode: "IL2087")]
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) }, messageCode: "IL2087")]
+ [ExpectedWarning ("IL2087", nameof (DataFlowTypeExtensions.RequiresPublicFields))]
+ [ExpectedWarning ("IL2087", nameof (DataFlowTypeExtensions.RequiresPublicMethods))]
public static void Test ()
{
typeof (T).RequiresPublicFields ();
@@ -157,12 +141,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow
class TypeRequiresPublicFieldsPassThrough<
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] TSource>
{
- [UnrecognizedReflectionAccessPattern (typeof (TypeRequiresPublicMethods<>), null, genericParameter: "T",
- messageCode: "IL2091", message: new string[] {
- nameof(TSource),
+ [ExpectedWarning ("IL2091", nameof (TSource),
"Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.TypeRequiresPublicFieldsPassThrough<TSource>",
"T",
- "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.TypeRequiresPublicMethods<T>" })]
+ "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.TypeRequiresPublicMethods<T>")]
public static void Test ()
{
TypeRequiresPublicFields<TSource>.Test ();
@@ -173,8 +155,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
class TypeRequiresNothingPassThrough<T>
{
- [UnrecognizedReflectionAccessPattern (typeof (TypeRequiresPublicFields<>), null, genericParameter: "T", messageCode: "IL2091")]
- [UnrecognizedReflectionAccessPattern (typeof (TypeRequiresPublicMethods<>), null, genericParameter: "T", messageCode: "IL2091")]
+ [ExpectedWarning ("IL2091", nameof (TypeRequiresPublicFields<T>))]
+ [ExpectedWarning ("IL2091", nameof (TypeRequiresPublicMethods<T>))]
public static void Test ()
{
TypeRequiresPublicFields<T>.Test ();
@@ -198,7 +180,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicMethods)] TBoth,
TNothing>
{
- [RecognizedReflectionAccessPattern]
public static void TestMultiple ()
{
typeof (TFields).RequiresPublicFields ();
@@ -211,7 +192,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (TNothing).RequiresNone ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) }, messageCode: "IL2087")]
+ [ExpectedWarning ("IL2087", nameof (DataFlowTypeExtensions.RequiresPublicMethods))]
public static void TestFields ()
{
typeof (TFields).RequiresPublicFields ();
@@ -219,7 +200,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (TFields).RequiresNone ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicFields), new Type[] { typeof (Type) }, messageCode: "IL2087")]
+ [ExpectedWarning ("IL2087", nameof (DataFlowTypeExtensions.RequiresPublicFields))]
public static void TestMethods ()
{
typeof (TMethods).RequiresPublicFields ();
@@ -227,7 +208,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (TMethods).RequiresNone ();
}
- [RecognizedReflectionAccessPattern]
public static void TestBoth ()
{
typeof (TBoth).RequiresPublicFields ();
@@ -235,8 +215,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (TBoth).RequiresNone ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicFields), new Type[] { typeof (Type) }, messageCode: "IL2087")]
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) }, messageCode: "IL2087")]
+ [ExpectedWarning ("IL2087", nameof (DataFlowTypeExtensions.RequiresPublicFields))]
+ [ExpectedWarning ("IL2087", nameof (DataFlowTypeExtensions.RequiresPublicMethods))]
public static void TestNothing ()
{
typeof (TNothing).RequiresPublicFields ();
@@ -245,7 +225,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
}
- [RecognizedReflectionAccessPattern]
static void TestBaseTypeGenericRequirements ()
{
new DerivedTypeWithInstantiatedGenericOnBase ();
@@ -256,14 +235,12 @@ namespace Mono.Linker.Tests.Cases.DataFlow
class GenericBaseTypeWithRequirements<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] T>
{
- [RecognizedReflectionAccessPattern]
public GenericBaseTypeWithRequirements ()
{
typeof (T).RequiresPublicFields ();
}
}
- [RecognizedReflectionAccessPattern]
class DerivedTypeWithInstantiatedGenericOnBase : GenericBaseTypeWithRequirements<TestType>
{
}
@@ -272,19 +249,17 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
class DerivedTypeWithInstantiationOverSelfOnBase : GenericBaseTypeWithRequirements<DerivedTypeWithInstantiationOverSelfOnBase>
{
}
- [UnrecognizedReflectionAccessPattern (typeof (GenericBaseTypeWithRequirements<>), null, genericParameter: "T", messageCode: "IL2091")]
+ [ExpectedWarning ("IL2091", nameof (GenericBaseTypeWithRequirements<T>))]
class DerivedTypeWithOpenGenericOnBase<T> : GenericBaseTypeWithRequirements<T>
{
- [UnrecognizedReflectionAccessPattern (typeof (GenericBaseTypeWithRequirements<>), null, genericParameter: "T", messageCode: "IL2091")]
+ [ExpectedWarning ("IL2091", nameof (GenericBaseTypeWithRequirements<T>))]
public DerivedTypeWithOpenGenericOnBase () { }
}
- [RecognizedReflectionAccessPattern]
class DerivedTypeWithOpenGenericOnBaseWithRequirements<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] T>
: GenericBaseTypeWithRequirements<T>
{
@@ -302,7 +277,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
class InterfaceImplementationTypeWithInstantiatedGenericOnBase : IGenericInterfaceTypeWithRequirements<TestType>
{
}
@@ -311,23 +285,20 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
class InterfaceImplementationTypeWithInstantiationOverSelfOnBase : IGenericInterfaceTypeWithRequiresAll<InterfaceImplementationTypeWithInstantiationOverSelfOnBase>
{
}
- [UnrecognizedReflectionAccessPattern (typeof (IGenericInterfaceTypeWithRequirements<>), null, genericParameter: "T", messageCode: "IL2091")]
+ [ExpectedWarning ("IL2091", nameof (IGenericInterfaceTypeWithRequirements<T>))]
class InterfaceImplementationTypeWithOpenGenericOnBase<T> : IGenericInterfaceTypeWithRequirements<T>
{
}
- [RecognizedReflectionAccessPattern]
class InterfaceImplementationTypeWithOpenGenericOnBaseWithRequirements<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] T>
: IGenericInterfaceTypeWithRequirements<T>
{
}
- [RecognizedReflectionAccessPattern]
static void TestDeepNestedTypesWithGenerics ()
{
RootTypeWithRequirements<TestType>.InnerTypeWithNoAddedGenerics.TestAccess ();
@@ -339,12 +310,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
// The message is not ideal since we report the TRoot to come from RootTypeWithRequirements/InnerTypeWIthNoAddedGenerics
// while it originates on RootTypeWithRequirements, but it's correct from IL's point of view.
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) },
- messageCode: "IL2087", message: new string[] {
- nameof(TRoot),
+ [ExpectedWarning ("IL2087", nameof (TRoot),
"Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.RootTypeWithRequirements<TRoot>.InnerTypeWithNoAddedGenerics",
"type",
- "DataFlowTypeExtensions.RequiresPublicMethods(Type)" })]
+ "DataFlowTypeExtensions.RequiresPublicMethods(Type)")]
public static void TestAccess ()
{
typeof (TRoot).RequiresPublicFields ();
@@ -353,7 +322,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
}
- [RecognizedReflectionAccessPattern]
static void TestTypeGenericRequirementsOnMembers ()
{
// Basically just root everything we need to test
@@ -379,50 +347,44 @@ namespace Mono.Linker.Tests.Cases.DataFlow
class TypeGenericRequirementsOnMembers<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] TOuter>
{
- [RecognizedReflectionAccessPattern]
public TypeRequiresPublicFields<TOuter> PublicFieldsField;
- [UnrecognizedReflectionAccessPattern (typeof (TypeRequiresPublicMethods<>), null, genericParameter: "T", messageCode: "IL2091")]
+ [ExpectedWarning ("IL2091", nameof (TypeRequiresPublicMethods<TOuter>))]
public TypeRequiresPublicMethods<TOuter> PublicMethodsField;
public TypeRequiresPublicFields<TOuter> PublicFieldsProperty {
- [RecognizedReflectionAccessPattern]
get;
- [RecognizedReflectionAccessPattern]
set;
}
public TypeRequiresPublicMethods<TOuter> PublicMethodsProperty {
- [UnrecognizedReflectionAccessPattern (typeof (TypeRequiresPublicMethods<>), null, genericParameter: "T", messageCode: "IL2091")]
+ [ExpectedWarning ("IL2091", nameof (TypeRequiresPublicMethods<TOuter>))]
get => null;
- [UnrecognizedReflectionAccessPattern (typeof (TypeRequiresPublicMethods<>), null, genericParameter: "T", messageCode: "IL2091")]
+ [ExpectedWarning ("IL2091", nameof (TypeRequiresPublicMethods<TOuter>))]
set { }
}
- [RecognizedReflectionAccessPattern]
public void PublicFieldsMethodParameter (TypeRequiresPublicFields<TOuter> param) { }
- [UnrecognizedReflectionAccessPattern (typeof (TypeRequiresPublicMethods<>), null, genericParameter: "T", messageCode: "IL2091")]
+ [ExpectedWarning ("IL2091", nameof (TypeRequiresPublicMethods<TOuter>))]
public void PublicMethodsMethodParameter (TypeRequiresPublicMethods<TOuter> param) { }
- [RecognizedReflectionAccessPattern]
public TypeRequiresPublicFields<TOuter> PublicFieldsMethodReturnValue () { return null; }
- [UnrecognizedReflectionAccessPattern (typeof (TypeRequiresPublicMethods<>), null, genericParameter: "T", messageCode: "IL2091")] // Return value
- [UnrecognizedReflectionAccessPattern (typeof (TypeRequiresPublicMethods<>), null, genericParameter: "T", messageCode: "IL2091")] // Compiler generated local variable
+ [ExpectedWarning ("IL2091", nameof (TypeRequiresPublicMethods<TOuter>))] // Return value
+ [ExpectedWarning ("IL2091", nameof (TypeRequiresPublicMethods<TOuter>))] // Compiler generated local variable
public TypeRequiresPublicMethods<TOuter> PublicMethodsMethodReturnValue () { return null; }
- [RecognizedReflectionAccessPattern]
public void PublicFieldsMethodLocalVariable ()
{
TypeRequiresPublicFields<TOuter> t = null;
}
- [UnrecognizedReflectionAccessPattern (typeof (TypeRequiresPublicMethods<>), null, genericParameter: "T", messageCode: "IL2091")]
+
+ [ExpectedWarning ("IL2091", nameof (TypeRequiresPublicMethods<TOuter>))]
public void PublicMethodsMethodLocalVariable ()
{
TypeRequiresPublicMethods<TOuter> t = null;
}
}
- [RecognizedReflectionAccessPattern]
static void TestPartialInstantiationTypes ()
{
_ = new PartialyInstantiatedFields<TestType> ();
@@ -437,27 +399,24 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
class PartialyInstantiatedFields<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] TOuter>
: BaseForPartialInstantiation<TOuter, TestType>
{
}
- [RecognizedReflectionAccessPattern]
class FullyInstantiatedOverPartiallyInstantiatedFields
: PartialyInstantiatedFields<TestType>
{
}
- [UnrecognizedReflectionAccessPattern (typeof (BaseForPartialInstantiation<,>), null, genericParameter: "TMethods", messageCode: "IL2091")]
+ [ExpectedWarning ("IL2091", nameof (BaseForPartialInstantiation<TestType, TOuter>), "'TMethods'")]
class PartialyInstantiatedMethods<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] TOuter>
: BaseForPartialInstantiation<TestType, TOuter>
{
- [UnrecognizedReflectionAccessPattern (typeof (BaseForPartialInstantiation<,>), null, genericParameter: "TMethods", messageCode: "IL2091")]
+ [ExpectedWarning ("IL2091", nameof (BaseForPartialInstantiation<TestType, TOuter>), "'TMethods'")]
public PartialyInstantiatedMethods () { }
}
- [RecognizedReflectionAccessPattern]
class FullyInstantiatedOverPartiallyInstantiatedMethods
: PartialyInstantiatedMethods<TestType>
{
@@ -472,7 +431,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
MethodRequiresNothingPassThrough<TestType> ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) }, messageCode: "IL2087")]
+ [ExpectedWarning ("IL2087", nameof (DataFlowTypeExtensions.RequiresPublicMethods))]
static void MethodRequiresPublicFields<
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] T> ()
{
@@ -481,7 +440,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (T).RequiresNone ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicFields), new Type[] { typeof (Type) }, messageCode: "IL2087")]
+ [ExpectedWarning ("IL2087", nameof (DataFlowTypeExtensions.RequiresPublicFields))]
static void MethodRequiresPublicMethods<
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] T> ()
{
@@ -497,8 +456,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (T).RequiresPublicFields ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicFields), new Type[] { typeof (Type) }, messageCode: "IL2087")]
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) }, messageCode: "IL2087")]
+ [ExpectedWarning ("IL2087", nameof (DataFlowTypeExtensions.RequiresPublicFields))]
+ [ExpectedWarning ("IL2087", nameof (DataFlowTypeExtensions.RequiresPublicMethods))]
static void MethodRequiresNothing<T> ()
{
typeof (T).RequiresPublicFields ();
@@ -506,7 +465,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (T).RequiresNone ();
}
- [UnrecognizedReflectionAccessPattern (typeof (GenericParameterDataFlow), nameof (MethodRequiresPublicMethods) + "<T>", new Type[0] { }, genericParameter: "T", messageCode: "IL2091")]
+ [ExpectedWarning ("IL2091", nameof (MethodRequiresPublicMethods), "'T'")]
static void MethodRequiresPublicFieldsPassThrough<
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] T> ()
{
@@ -515,8 +474,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
MethodRequiresNothing<T> ();
}
- [UnrecognizedReflectionAccessPattern (typeof (GenericParameterDataFlow), nameof (MethodRequiresPublicFields) + "<T>", new Type[0] { }, genericParameter: "T", messageCode: "IL2091")]
- [UnrecognizedReflectionAccessPattern (typeof (GenericParameterDataFlow), nameof (MethodRequiresPublicMethods) + "<T>", new Type[0] { }, genericParameter: "T", messageCode: "IL2091")]
+ [ExpectedWarning ("IL2091", nameof (MethodRequiresPublicFields), "'T'")]
+ [ExpectedWarning ("IL2091", nameof (MethodRequiresPublicMethods), "'T'")]
static void MethodRequiresNothingPassThrough<T> ()
{
MethodRequiresPublicFields<T> ();
@@ -549,27 +508,20 @@ namespace Mono.Linker.Tests.Cases.DataFlow
class BaseTypeWithGenericMethod
{
- [RecognizedReflectionAccessPattern]
public static void StaticRequiresPublicFields<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] T> ()
=> typeof (T).RequiresPublicFields ();
- [RecognizedReflectionAccessPattern]
public void InstanceRequiresPublicFields<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] T> ()
=> typeof (T).RequiresPublicFields ();
- [RecognizedReflectionAccessPattern]
public virtual void VirtualRequiresPublicFields<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] T> ()
=> typeof (T).RequiresPublicFields ();
- [RecognizedReflectionAccessPattern]
public static void StaticRequiresPublicMethods<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] T> ()
=> typeof (T).RequiresPublicMethods ();
- [RecognizedReflectionAccessPattern]
public void InstanceRequiresPublicMethods<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]T> ()
=> typeof (T).RequiresPublicMethods ();
- [RecognizedReflectionAccessPattern]
public virtual void VirtualRequiresPublicMethods<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]T> ()
=> typeof (T).RequiresPublicMethods ();
- [RecognizedReflectionAccessPattern]
public static void StaticRequiresMultipleGenericParams<
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] TFields,
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] TMethods> ()
@@ -588,101 +540,90 @@ namespace Mono.Linker.Tests.Cases.DataFlow
class TypeWithInstantiatedGenericMethodViaGenericParameter<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] TOuter>
: BaseTypeWithGenericMethod, IInterfaceWithGenericMethod
{
- [UnrecognizedReflectionAccessPattern (typeof (BaseTypeWithGenericMethod), nameof (BaseTypeWithGenericMethod.StaticRequiresPublicMethods) + "<T>", new Type[0] { }, genericParameter: "T",
- messageCode: "IL2091", message: new string[] {
- "TInner",
- "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.TypeWithInstantiatedGenericMethodViaGenericParameter<TOuter>.StaticRequiresPublicFields<TInner>()",
- "T",
- "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.BaseTypeWithGenericMethod.StaticRequiresPublicMethods<T>()" })]
+ [ExpectedWarning ("IL2091",
+ "'TInner'",
+ "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.TypeWithInstantiatedGenericMethodViaGenericParameter<TOuter>.StaticRequiresPublicFields<TInner>()",
+ "'T'",
+ "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.BaseTypeWithGenericMethod.StaticRequiresPublicMethods<T>()")]
public static void StaticRequiresPublicFields<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] TInner> ()
{
StaticRequiresPublicFields<TInner> ();
StaticRequiresPublicMethods<TInner> ();
}
- [UnrecognizedReflectionAccessPattern (typeof (BaseTypeWithGenericMethod), nameof (BaseTypeWithGenericMethod.StaticRequiresPublicMethods) + "<T>", new Type[0] { }, genericParameter: "T",
- messageCode: "IL2091", message: new string[] {
- "TOuter",
- "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.TypeWithInstantiatedGenericMethodViaGenericParameter<TOuter>",
- "T",
- "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.BaseTypeWithGenericMethod.StaticRequiresPublicMethods<T>()" })]
+ [ExpectedWarning ("IL2091",
+ "'TOuter'",
+ "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.TypeWithInstantiatedGenericMethodViaGenericParameter<TOuter>",
+ "'T'",
+ "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.BaseTypeWithGenericMethod.StaticRequiresPublicMethods<T>()")]
public static void StaticRequiresPublicFieldsNonGeneric ()
{
StaticRequiresPublicFields<TOuter> ();
StaticRequiresPublicMethods<TOuter> ();
}
- [RecognizedReflectionAccessPattern]
public static void StaticPartialInstantiation ()
{
StaticRequiresMultipleGenericParams<TOuter, TestType> ();
}
- [UnrecognizedReflectionAccessPattern (typeof (BaseTypeWithGenericMethod), nameof (BaseTypeWithGenericMethod.StaticRequiresMultipleGenericParams) + "<TFields,TMethods>", new Type[0] { }, genericParameter: "TMethods",
- messageCode: "IL2091", message: new string[] {
- "TOuter",
- "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.TypeWithInstantiatedGenericMethodViaGenericParameter<TOuter>",
- "TMethods",
- "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.BaseTypeWithGenericMethod.StaticRequiresMultipleGenericParams<TFields,TMethods>()" })]
+ [ExpectedWarning ("IL2091",
+ "'TOuter'",
+ "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.TypeWithInstantiatedGenericMethodViaGenericParameter<TOuter>",
+ "'TMethods'",
+ "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.BaseTypeWithGenericMethod.StaticRequiresMultipleGenericParams<TFields,TMethods>()")]
public static void StaticPartialInstantiationUnrecognized ()
{
StaticRequiresMultipleGenericParams<TestType, TOuter> ();
}
- [UnrecognizedReflectionAccessPattern (typeof (BaseTypeWithGenericMethod), nameof (BaseTypeWithGenericMethod.InstanceRequiresPublicMethods) + "<T>", new Type[0] { }, genericParameter: "T",
- messageCode: "IL2091", message: new string[] {
- "TInner",
- "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.TypeWithInstantiatedGenericMethodViaGenericParameter<TOuter>.InstanceRequiresPublicFields<TInner>()",
- "T",
- "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.BaseTypeWithGenericMethod.InstanceRequiresPublicMethods<T>()" })]
+ [ExpectedWarning ("IL2091",
+ "'TInner'",
+ "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.TypeWithInstantiatedGenericMethodViaGenericParameter<TOuter>.InstanceRequiresPublicFields<TInner>()",
+ "'T'",
+ "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.BaseTypeWithGenericMethod.InstanceRequiresPublicMethods<T>()")]
public void InstanceRequiresPublicFields<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] TInner> ()
{
InstanceRequiresPublicFields<TInner> ();
InstanceRequiresPublicMethods<TInner> ();
}
- [UnrecognizedReflectionAccessPattern (typeof (BaseTypeWithGenericMethod), nameof (BaseTypeWithGenericMethod.InstanceRequiresPublicMethods) + "<T>", new Type[0] { }, genericParameter: "T",
- messageCode: "IL2091", message: new string[] {
- "TOuter",
- "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.TypeWithInstantiatedGenericMethodViaGenericParameter<TOuter>",
- "T",
- "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.BaseTypeWithGenericMethod.InstanceRequiresPublicMethods<T>()" })]
+ [ExpectedWarning ("IL2091",
+ "'TOuter'",
+ "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.TypeWithInstantiatedGenericMethodViaGenericParameter<TOuter>",
+ "'T'",
+ "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.BaseTypeWithGenericMethod.InstanceRequiresPublicMethods<T>()")]
public void InstanceRequiresPublicFieldsNonGeneric ()
{
InstanceRequiresPublicFields<TOuter> ();
InstanceRequiresPublicMethods<TOuter> ();
}
- [RecognizedReflectionAccessPattern]
public override void VirtualRequiresPublicFields<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] T> ()
{
typeof (T).RequiresPublicFields ();
}
- [RecognizedReflectionAccessPattern]
public override void VirtualRequiresPublicMethods<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] T> ()
{
typeof (T).RequiresPublicMethods ();
}
- [RecognizedReflectionAccessPattern]
public void InterfaceRequiresPublicFields<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] T> ()
{
typeof (T).RequiresPublicFields (); ;
}
- [RecognizedReflectionAccessPattern]
public void InterfaceRequiresPublicMethods<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] T> ()
{
typeof (T).RequiresPublicMethods ();
}
- [UnrecognizedReflectionAccessPattern (typeof (IInterfaceWithGenericMethod), nameof (IInterfaceWithGenericMethod.InterfaceRequiresPublicMethods) + "<T>", new Type[0] { }, genericParameter: "T",
- messageCode: "IL2091", message: new string[] {
- "TOuter",
- "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.TypeWithInstantiatedGenericMethodViaGenericParameter<TOuter>",
- "T",
- "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.IInterfaceWithGenericMethod.InterfaceRequiresPublicMethods<T>()" })]
+ [ExpectedWarning ("IL2091",
+ "'TOuter'",
+ "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.TypeWithInstantiatedGenericMethodViaGenericParameter<TOuter>",
+ "'T'",
+ "Mono.Linker.Tests.Cases.DataFlow.GenericParameterDataFlow.IInterfaceWithGenericMethod.InterfaceRequiresPublicMethods<T>()")]
public void CallInterface ()
{
IInterfaceWithGenericMethod interfaceInstance = (IInterfaceWithGenericMethod) this;
@@ -701,7 +642,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
MethodMultipleWithDifferentRequirements_TestNothing<TestType, TestType, TestType, TestType> ();
}
- [RecognizedReflectionAccessPattern]
static void MethodMultipleWithDifferentRequirements_TestMultiple<
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] TFields,
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] TMethods,
@@ -718,7 +658,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (TNothing).RequiresNone ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) }, messageCode: "IL2087")]
+ [ExpectedWarning ("IL2087", nameof (DataFlowTypeExtensions.RequiresPublicMethods))]
static void MethodMultipleWithDifferentRequirements_TestFields<
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] TFields,
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] TMethods,
@@ -730,7 +670,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (TFields).RequiresNone ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicFields), new Type[] { typeof (Type) }, messageCode: "IL2087")]
+ [ExpectedWarning ("IL2087", nameof (DataFlowTypeExtensions.RequiresPublicFields))]
static void MethodMultipleWithDifferentRequirements_TestMethods<
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] TFields,
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] TMethods,
@@ -753,8 +693,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (TBoth).RequiresNone ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicFields), new Type[] { typeof (Type) }, messageCode: "IL2087")]
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) }, messageCode: "IL2087")]
+ [ExpectedWarning ("IL2087", nameof (DataFlowTypeExtensions.RequiresPublicFields))]
+ [ExpectedWarning ("IL2087", nameof (DataFlowTypeExtensions.RequiresPublicMethods))]
static void MethodMultipleWithDifferentRequirements_TestNothing<
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] TFields,
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] TMethods,
@@ -797,29 +737,25 @@ namespace Mono.Linker.Tests.Cases.DataFlow
// This is OK since we know it's null, so MakeGenericType is effectively a no-op (will throw)
// so no validation necessary.
- [RecognizedReflectionAccessPattern]
static void TestNullType ()
{
Type nullType = null;
nullType.MakeGenericType (typeof (TestType));
}
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.MakeGenericType), new Type[] { typeof (Type[]) },
- messageCode: "IL2055")]
+ [ExpectedWarning ("IL2055", nameof (Type.MakeGenericType))]
static void TestUnknownInput (Type inputType)
{
inputType.MakeGenericType (typeof (TestType));
}
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.MakeGenericType), new Type[] { typeof (Type[]) },
- messageCode: "IL2055")]
+ [ExpectedWarning ("IL2055", nameof (Type.MakeGenericType))]
static void TestWithUnknownTypeArray (Type[] types)
{
typeof (GenericWithPublicFieldsArgument<>).MakeGenericType (types);
}
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.MakeGenericType), new Type[] { typeof (Type[]) },
- messageCode: "IL2055")]
+ [ExpectedWarning ("IL2055", nameof (Type.MakeGenericType))]
static void TestWithArrayUnknownIndexSet (int indexToSet)
{
Type[] types = new Type[1];
@@ -827,8 +763,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (GenericWithPublicFieldsArgument<>).MakeGenericType (types);
}
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.MakeGenericType), new Type[] { typeof (Type[]) },
- messageCode: "IL2055")]
+ [ExpectedWarning ("IL2055", nameof (Type.MakeGenericType))]
static void TestWithArrayUnknownLengthSet (int arrayLen)
{
Type[] types = new Type[arrayLen];
@@ -836,7 +771,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (GenericWithPublicFieldsArgument<>).MakeGenericType (types);
}
- [RecognizedReflectionAccessPattern]
static void TestNoArguments ()
{
typeof (TypeMakeGenericNoArguments).MakeGenericType ();
@@ -846,7 +780,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
static void TestWithRequirements ()
{
// Currently this is not analyzable since we don't track array elements.
@@ -854,7 +787,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (GenericWithPublicFieldsArgument<>).MakeGenericType (typeof (TestType));
}
- [RecognizedReflectionAccessPattern]
static void TestWithRequirementsFromParam (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] Type type)
{
@@ -870,7 +802,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (GenericWithPublicFieldsArgument<>).MakeGenericType (type);
}
- [RecognizedReflectionAccessPattern]
static void TestWithRequirementsFromGenericParam<
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] T> ()
{
@@ -890,13 +821,11 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
static void TestWithNoRequirements ()
{
typeof (GenericWithNoRequirements<>).MakeGenericType (typeof (TestType));
}
- [RecognizedReflectionAccessPattern]
static void TestWithNoRequirementsFromParam (Type type)
{
typeof (GenericWithNoRequirements<>).MakeGenericType (type);
@@ -906,7 +835,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
static void TestWithMultipleArgumentsWithRequirements ()
{
typeof (GenericWithMultipleArgumentsWithRequirements<,>).MakeGenericType (typeof (TestType), typeof (TestType));
@@ -918,7 +846,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
static void TestWithNewConstraint ()
{
typeof (GenericWithNewConstraint<>).MakeGenericType (typeof (TestType));
@@ -928,7 +855,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
static void TestWithStructConstraint ()
{
typeof (GenericWithStructConstraint<>).MakeGenericType (typeof (TestType));
@@ -938,7 +864,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
static void TestWithUnmanagedConstraint ()
{
typeof (GenericWithUnmanagedConstraint<>).MakeGenericType (typeof (TestType));
@@ -948,7 +873,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
static void TestWithNullable ()
{
typeof (Nullable<>).MakeGenericType (typeof (TestType));
@@ -995,38 +919,33 @@ namespace Mono.Linker.Tests.Cases.DataFlow
TestWithUnmanagedConstraint ();
}
- [RecognizedReflectionAccessPattern]
static void TestNullMethod ()
{
MethodInfo mi = null;
mi.MakeGenericMethod (typeof (TestType));
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodInfo), nameof (MethodInfo.MakeGenericMethod), new Type[] { typeof (Type[]) },
- messageCode: "IL2060")]
+ [ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod))]
static void TestUnknownMethod (MethodInfo mi)
{
mi.MakeGenericMethod (typeof (TestType));
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodInfo), nameof (MethodInfo.MakeGenericMethod), new Type[] { typeof (Type[]) },
- messageCode: "IL2060")]
+ [ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod))]
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);
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodInfo), nameof (MethodInfo.MakeGenericMethod), new Type[] { typeof (Type[]) },
- messageCode: "IL2060")]
+ [ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod))]
static void TestWithUnknownTypeArray (Type[] types)
{
typeof (MakeGenericMethod).GetMethod (nameof (GenericWithRequirements), BindingFlags.Static)
.MakeGenericMethod (types);
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodInfo), nameof (MethodInfo.MakeGenericMethod), new Type[] { typeof (Type[]) },
- messageCode: "IL2060")]
+ [ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod))]
static void TestWithArrayUnknownIndexSet (int indexToSet)
{
Type[] types = new Type[1];
@@ -1035,8 +954,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
.MakeGenericMethod (types);
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodInfo), nameof (MethodInfo.MakeGenericMethod), new Type[] { typeof (Type[]) },
- messageCode: "IL2060")]
+ [ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod))]
static void TestWithArrayUnknownIndexSetByRef (int indexToSet)
{
Type[] types = new Type[1];
@@ -1047,8 +965,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
.MakeGenericMethod (types);
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodInfo), nameof (MethodInfo.MakeGenericMethod), new Type[] { typeof (Type[]) },
- messageCode: "IL2060")]
+ [ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod))]
static void TestWithArrayUnknownLengthSet (int arrayLen)
{
Type[] types = new Type[arrayLen];
@@ -1061,8 +978,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodInfo), nameof (MethodInfo.MakeGenericMethod), new Type[] { typeof (Type[]) },
- messageCode: "IL2060")]
+ [ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod))]
static void TestWithArrayPassedToAnotherMethod ()
{
Type[] types = new Type[1];
@@ -1072,7 +988,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
.MakeGenericMethod (types);
}
- [RecognizedReflectionAccessPattern]
static void TestWithNoArguments ()
{
typeof (MakeGenericMethod).GetMethod (nameof (NonGenericMethod), BindingFlags.Static | BindingFlags.NonPublic)
@@ -1082,7 +997,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
// This should not warn since we can't be always sure about the exact overload as we don't support
// method parameter signature matching, and thus the GetMethod may return multiple potential methods.
// It can happen that some are generic and some are not. The analysis should not fail on this.
- [RecognizedReflectionAccessPattern]
static void TestWithArgumentsButNonGenericMethod ()
{
typeof (MakeGenericMethod).GetMethod (nameof (NonGenericMethod), BindingFlags.Static | BindingFlags.NonPublic)
@@ -1093,14 +1007,12 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
static void TestWithRequirements ()
{
typeof (MakeGenericMethod).GetMethod (nameof (GenericWithRequirements), BindingFlags.Static)
.MakeGenericMethod (typeof (TestType));
}
- [RecognizedReflectionAccessPattern]
static void TestWithRequirementsFromParam (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] Type type)
{
@@ -1116,15 +1028,13 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
- [RecognizedReflectionAccessPattern]
static void TestWithRequirementsViaRuntimeMethod ()
{
typeof (MakeGenericMethod).GetRuntimeMethod (nameof (GenericWithRequirements), Type.EmptyTypes)
.MakeGenericMethod (typeof (TestType));
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodInfo), nameof (MethodInfo.MakeGenericMethod), new Type[] { typeof (Type[]) },
- messageCode: "IL2060")]
+ [ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod))]
static void TestWithRequirementsButNoTypeArguments ()
{
typeof (MakeGenericMethod).GetMethod (nameof (GenericWithRequirements), BindingFlags.Static)
@@ -1135,23 +1045,20 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
static void TestWithMultipleKnownGenericParameters ()
{
typeof (MakeGenericMethod).GetMethod (nameof (GenericMultipleParameters), BindingFlags.Static)
.MakeGenericMethod (typeof (TestType), typeof (TestType), typeof (TestType));
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodInfo), nameof (MethodInfo.MakeGenericMethod), new Type[] { typeof (Type[]) },
- messageCode: "IL2060")]
+ [ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod))]
static void TestWithOneUnknownGenericParameter (Type[] types)
{
typeof (MakeGenericMethod).GetMethod (nameof (GenericMultipleParameters), BindingFlags.Static)
.MakeGenericMethod (typeof (TestType), typeof (TestStruct), types[0]);
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodInfo), nameof (MethodInfo.MakeGenericMethod), new Type[] { typeof (Type[]) },
- messageCode: "IL2060")]
+ [ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod))]
static void TestWithPartiallyInitializedGenericTypeArray ()
{
Type[] types = new Type[3];
@@ -1161,7 +1068,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
.MakeGenericMethod (types);
}
- [RecognizedReflectionAccessPattern]
static void TestWithConditionalGenericTypeSet (bool thirdParameterIsStruct)
{
Type[] types = new Type[3];
@@ -1183,21 +1089,18 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
static void TestWithNoRequirements ()
{
typeof (MakeGenericMethod).GetMethod (nameof (GenericWithNoRequirements), BindingFlags.Static)
.MakeGenericMethod (typeof (TestType));
}
- [RecognizedReflectionAccessPattern]
static void TestWithNoRequirementsFromParam (Type type)
{
typeof (MakeGenericMethod).GetMethod (nameof (GenericWithNoRequirements), BindingFlags.Static)
.MakeGenericMethod (type);
}
- [RecognizedReflectionAccessPattern]
static void TestWithNoRequirementsViaRuntimeMethod ()
{
typeof (MakeGenericMethod).GetRuntimeMethod (nameof (GenericWithNoRequirements), Type.EmptyTypes)
@@ -1205,7 +1108,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
// There are no requirements, so no warnings
- [RecognizedReflectionAccessPattern]
static void TestWithNoRequirementsUnknownType (Type type)
{
typeof (MakeGenericMethod).GetMethod (nameof (GenericWithNoRequirements))
@@ -1213,7 +1115,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
// There are no requirements, so no warnings
- [RecognizedReflectionAccessPattern]
static void TestWithNoRequirementsWrongNumberOfTypeParameters ()
{
typeof (MakeGenericMethod).GetMethod (nameof (GenericWithNoRequirements))
@@ -1221,7 +1122,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
// There are no requirements, so no warnings
- [RecognizedReflectionAccessPattern]
static void TestWithNoRequirementsUnknownArrayElement ()
{
Type[] types = new Type[1];
@@ -1234,7 +1134,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
- [RecognizedReflectionAccessPattern]
static void TestWithMultipleArgumentsWithRequirements ()
{
typeof (MakeGenericMethod).GetMethod (nameof (GenericWithMultipleArgumentsWithRequirements), BindingFlags.Static | BindingFlags.NonPublic)
@@ -1247,7 +1146,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
static void TestWithNewConstraint ()
{
typeof (MakeGenericMethod).GetMethod (nameof (GenericWithNewConstraint), BindingFlags.Static | BindingFlags.NonPublic)
@@ -1259,7 +1157,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
var t = new T ();
}
- [RecognizedReflectionAccessPattern]
static void TestWithStructConstraint ()
{
typeof (MakeGenericMethod).GetMethod (nameof (GenericWithStructConstraint), BindingFlags.Static | BindingFlags.NonPublic)
@@ -1271,7 +1168,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
var t = new T ();
}
- [RecognizedReflectionAccessPattern]
static void TestWithUnmanagedConstraint ()
{
typeof (MakeGenericMethod).GetMethod (nameof (GenericWithUnmanagedConstraint), BindingFlags.Static | BindingFlags.NonPublic)
@@ -1284,19 +1180,16 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
}
- [RecognizedReflectionAccessPattern]
static void TestNewConstraintSatisfiesParameterlessConstructor<T> () where T : new()
{
RequiresParameterlessConstructor<T> ();
}
- [RecognizedReflectionAccessPattern]
static void TestStructConstraintSatisfiesParameterlessConstructor<T> () where T : struct
{
RequiresParameterlessConstructor<T> ();
}
- [RecognizedReflectionAccessPattern]
static void TestUnmanagedConstraintSatisfiesParameterlessConstructor<T> () where T : unmanaged
{
RequiresParameterlessConstructor<T> ();
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/GetNestedTypeOnAllAnnotatedType.cs b/test/Mono.Linker.Tests.Cases/DataFlow/GetNestedTypeOnAllAnnotatedType.cs
index e7da76ae9..fbf1c966a 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/GetNestedTypeOnAllAnnotatedType.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/GetNestedTypeOnAllAnnotatedType.cs
@@ -13,68 +13,62 @@ using Mono.Linker.Tests.Cases.Expectations.Helpers;
namespace Mono.Linker.Tests.Cases.DataFlow
{
- [RecognizedReflectionAccessPattern]
+ [ExpectedNoWarnings]
[SkipKeptItemsValidation]
class GetNestedTypeOnAllAnnotatedType
{
- [RecognizedReflectionAccessPattern]
static void Main ()
{
- TestOnAllAnnotatedParameter (typeof (GetNestedTypeOnAllAnnotatedType));
- TestOnNonAllAnnotatedParameter (typeof (GetNestedTypeOnAllAnnotatedType));
- TestWithBindingFlags (typeof (GetNestedTypeOnAllAnnotatedType));
- TestWithUnknownBindingFlags (BindingFlags.Public, typeof (GetNestedTypeOnAllAnnotatedType));
- TestUnsupportedBindingFlags (typeof (GetNestedTypeOnAllAnnotatedType));
+ TestOnAllAnnotatedParameter (typeof (TestType));
+ TestOnNonAllAnnotatedParameter (typeof (TestType));
+ TestWithBindingFlags (typeof (TestType));
+ TestWithUnknownBindingFlags (BindingFlags.Public, typeof (TestType));
+ TestUnsupportedBindingFlags (typeof (TestType));
TestWithNull ();
- TestIfElse (1, typeof (GetNestedTypeOnAllAnnotatedType), typeof (GetNestedTypeOnAllAnnotatedType));
- TestSwitchAllValid (1, typeof (GetNestedTypeOnAllAnnotatedType));
+ TestIfElse (1, typeof (TestType), typeof (TestType));
+ TestSwitchAllValid (1, typeof (TestType));
TestOnKnownTypeOnly ();
}
- [RecognizedReflectionAccessPattern]
static void TestOnAllAnnotatedParameter ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] Type parentType)
{
- var nestedType = parentType.GetNestedType (nameof (NestedType));
+ var nestedType = parentType.GetNestedType (nameof (TestType.NestedType));
nestedType.RequiresAll ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresAll), new Type[] { typeof (Type) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresAll))]
static void TestOnNonAllAnnotatedParameter ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicNestedTypes)] Type parentType)
{
- var nestedType = parentType.GetNestedType (nameof (NestedType));
+ var nestedType = parentType.GetNestedType (nameof (TestType.NestedType));
nestedType.RequiresAll ();
}
- [RecognizedReflectionAccessPattern]
static void TestWithBindingFlags ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] Type parentType)
{
- var nestedType = parentType.GetNestedType (nameof (NestedType), BindingFlags.Public);
+ var nestedType = parentType.GetNestedType (nameof (TestType.NestedType), BindingFlags.Public);
nestedType.RequiresAll ();
}
- [RecognizedReflectionAccessPattern]
static void TestWithUnknownBindingFlags (BindingFlags bindingFlags, [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] Type parentType)
{
- var nestedType = parentType.GetNestedType (nameof (NestedType), bindingFlags);
+ var nestedType = parentType.GetNestedType (nameof (TestType.NestedType), bindingFlags);
nestedType.RequiresAll ();
}
- [RecognizedReflectionAccessPattern]
static void TestUnsupportedBindingFlags ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] Type parentType)
{
- var nestedType = parentType.GetNestedType (nameof (NestedType), BindingFlags.IgnoreCase);
+ var nestedType = parentType.GetNestedType (nameof (TestType.NestedType), BindingFlags.IgnoreCase);
nestedType.RequiresAll ();
}
- [RecognizedReflectionAccessPattern]
static void TestWithNull ()
{
Type parentType = null;
- var nestedType = parentType.GetNestedType (nameof (NestedType));
+ var nestedType = parentType.GetNestedType (nameof (TestType.NestedType));
nestedType.RequiresAll ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresAll), new Type[] { typeof (Type) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresAll))]
static void TestIfElse (int number, [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] Type parentWithAll, [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicNestedTypes)] Type parentWithoutAll)
{
Type typeOfParent;
@@ -83,35 +77,36 @@ namespace Mono.Linker.Tests.Cases.DataFlow
} else {
typeOfParent = parentWithoutAll;
}
- var nestedType = typeOfParent.GetNestedType (nameof (NestedType));
+ var nestedType = typeOfParent.GetNestedType (nameof (TestType.NestedType));
nestedType.RequiresAll ();
}
- [RecognizedReflectionAccessPattern]
static void TestSwitchAllValid (int number, [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] Type parentWithAll)
{
Type typeOfParent = number switch {
1 => parentWithAll,
2 => null,
- 3 => typeof (GetNestedTypeOnAllAnnotatedType)
+ 3 => typeof (TestType)
};
- var nestedType = typeOfParent.GetNestedType (nameof (NestedType));
+ var nestedType = typeOfParent.GetNestedType (nameof (TestType.NestedType));
nestedType.RequiresAll ();
}
- [RecognizedReflectionAccessPattern]
static void TestOnKnownTypeOnly ()
{
- typeof (GetNestedTypeOnAllAnnotatedType).GetNestedType (nameof (NestedType)).RequiresAll ();
+ typeof (TestType).GetNestedType (nameof (TestType.NestedType)).RequiresAll ();
}
- private class NestedType
+ class TestType
{
- NestedType () { }
- public static int PublicStaticInt;
- public void Method () { }
- int Prop { get; set; }
+ public class NestedType
+ {
+ NestedType () { }
+ public static int PublicStaticInt;
+ public void Method () { }
+ int Prop { get; set; }
+ }
}
}
}
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/GetTypeDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/GetTypeDataFlow.cs
index 5dc272f0f..289916c27 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/GetTypeDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/GetTypeDataFlow.cs
@@ -6,12 +6,14 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Helpers;
namespace Mono.Linker.Tests.Cases.DataFlow
{
// Note: this test's goal is to validate that the product correctly reports unrecognized patterns
- // - so the main validation is done by the UnrecognizedReflectionAccessPattern attributes.
+ // - so the main validation is done by the ExpectedWarning attributes.
[SkipKeptItemsValidation]
+ [ExpectedNoWarnings]
public class GetTypeDataFlow
{
public static void Main ()
@@ -35,59 +37,59 @@ namespace Mono.Linker.Tests.Cases.DataFlow
// Type.GetType over two params
}
- [UnrecognizedReflectionAccessPattern (typeof (GetTypeDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")]
- [UnrecognizedReflectionAccessPattern (typeof (GetTypeDataFlow), nameof (RequireNonPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresPublicConstructors))]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors))]
static void TestPublicParameterlessConstructor ()
{
Type type = Type.GetType (GetStringTypeWithPublicParameterlessConstructor ());
- RequirePublicParameterlessConstructor (type);
- RequirePublicConstructors (type);
- RequireNonPublicConstructors (type);
- RequireNothing (type);
+ type.RequiresPublicParameterlessConstructor ();
+ type.RequiresPublicConstructors ();
+ type.RequiresNonPublicConstructors ();
+ type.RequiresNone ();
}
- [UnrecognizedReflectionAccessPattern (typeof (GetTypeDataFlow), nameof (RequireNonPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors))]
static void TestPublicConstructors ()
{
Type type = Type.GetType (GetStringTypeWithPublicConstructors ());
- RequirePublicParameterlessConstructor (type);
- RequirePublicConstructors (type);
- RequireNonPublicConstructors (type);
- RequireNothing (type);
+ type.RequiresPublicParameterlessConstructor ();
+ type.RequiresPublicConstructors ();
+ type.RequiresNonPublicConstructors ();
+ type.RequiresNone ();
}
- [UnrecognizedReflectionAccessPattern (typeof (GetTypeDataFlow), nameof (RequirePublicParameterlessConstructor), new Type[] { typeof (Type) }, messageCode: "IL2072")]
- [UnrecognizedReflectionAccessPattern (typeof (GetTypeDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresPublicParameterlessConstructor))]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresPublicConstructors))]
static void TestConstructors ()
{
Type type = Type.GetType (GetStringTypeWithNonPublicConstructors ());
- RequirePublicParameterlessConstructor (type);
- RequirePublicConstructors (type);
- RequireNonPublicConstructors (type);
- RequireNothing (type);
+ type.RequiresPublicParameterlessConstructor ();
+ type.RequiresPublicConstructors ();
+ type.RequiresNonPublicConstructors ();
+ type.RequiresNone ();
}
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (GetType), new Type[] { typeof (string) }, messageCode: "IL2057")]
+ [ExpectedWarning ("IL2057", nameof (GetType))]
static void TestUnknownType ()
{
Type type = Type.GetType (GetStringUnkownType ());
}
- [UnrecognizedReflectionAccessPattern (typeof (GetTypeDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresPublicConstructors))]
static void TestTypeNameFromParameter (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
string typeName)
{
- RequirePublicConstructors (Type.GetType (typeName));
+ Type.GetType (typeName).RequiresPublicConstructors ();
}
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
static string _typeNameWithPublicParameterlessConstructor;
- [UnrecognizedReflectionAccessPattern (typeof (GetTypeDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresPublicConstructors))]
static void TestTypeNameFromField ()
{
- RequirePublicConstructors (Type.GetType (_typeNameWithPublicParameterlessConstructor));
+ Type.GetType (_typeNameWithPublicParameterlessConstructor).RequiresPublicConstructors ();
}
static int _switchOnField;
@@ -113,16 +115,13 @@ namespace Mono.Linker.Tests.Cases.DataFlow
Type.GetType (typeName);
}
- [RecognizedReflectionAccessPattern]
static void TestStringEmpty ()
{
Type.GetType (string.Empty);
}
- [UnrecognizedReflectionAccessPattern (typeof (GetTypeDataFlow), nameof (RequireNonPublicConstructors), new Type[] { typeof (Type) },
- messageCode: "IL2072", message: new string[] { "GetType" })]
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetType), new Type[] { typeof (string) },
- messageCode: "IL2057", message: new string[] { "System.Type.GetType(String)" })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors), nameof (Type.GetType))]
+ [ExpectedWarning ("IL2057", "System.Type.GetType(String)")]
static void TestMultipleMixedValues ()
{
string typeName = null;
@@ -141,29 +140,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
break;
}
- RequireNonPublicConstructors (Type.GetType (typeName));
- }
-
- private static void RequirePublicParameterlessConstructor (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
- Type type)
- {
- }
-
- private static void RequirePublicConstructors (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
- Type type)
- {
- }
-
- private static void RequireNonPublicConstructors (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors)]
- Type type)
- {
- }
-
- private static void RequireNothing (Type type)
- {
+ Type.GetType (typeName).RequiresNonPublicConstructors ();
}
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/GetTypeInfoDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/GetTypeInfoDataFlow.cs
new file mode 100644
index 000000000..e99d87bc5
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/GetTypeInfoDataFlow.cs
@@ -0,0 +1,39 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Diagnostics.CodeAnalysis;
+using System.Reflection;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Helpers;
+
+namespace Mono.Linker.Tests.Cases.DataFlow
+{
+ [SkipKeptItemsValidation]
+ [ExpectedNoWarnings]
+ class GetTypeInfoDataFlow
+ {
+ public static void Main ()
+ {
+ TestNoAnnotations (typeof (TestType));
+ TestWithAnnotations (typeof (TestType));
+ }
+
+ [ExpectedWarning ("IL2067", nameof (DataFlowTypeExtensions.RequiresPublicMethods))]
+ static void TestNoAnnotations (Type t)
+ {
+ t.GetTypeInfo ().RequiresPublicMethods ();
+ t.GetTypeInfo ().RequiresNone ();
+ }
+
+ [ExpectedWarning ("IL2067", nameof (DataFlowTypeExtensions.RequiresPublicFields))]
+ static void TestWithAnnotations ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type t)
+ {
+ t.GetTypeInfo ().RequiresPublicMethods ();
+ t.GetTypeInfo ().RequiresPublicFields ();
+ t.GetTypeInfo ().RequiresNone ();
+ }
+
+ class TestType { }
+ }
+}
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/IReflectDataflow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/IReflectDataflow.cs
index 2a12479a1..9506cf0db 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/IReflectDataflow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/IReflectDataflow.cs
@@ -9,6 +9,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
// Hits what appears to be a bug in the tool
// Could not initialize vtable of class(0x02000007) .MyReflect due to VTable setup of type Mono.Linker.Tests.Cases.DataFlow.IReflectDataflow+MyReflect failed assembly:/tmp/linker_tests/output/test.exe type:MyReflect member:(null)
[SkipPeVerify]
+ [ExpectedNoWarnings]
class IReflectDataflow
{
[ExpectBodyModified]
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/LocalDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/LocalDataFlow.cs
index eca6e9368..379ff5293 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/LocalDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/LocalDataFlow.cs
@@ -1,12 +1,17 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
using System;
using System.Diagnostics.CodeAnalysis;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Helpers;
namespace Mono.Linker.Tests.Cases.DataFlow
{
// Note: this test's goal is to validate that the product correctly reports unrecognized patterns
- // - so the main validation is done by the UnrecognizedReflectionAccessPattern attributes.
+ // - so the main validation is done by the ExpectedWarning attributes.
[SkipKeptItemsValidation]
+ [ExpectedNoWarnings]
public class LocalDataFlow
{
public static void Main ()
@@ -18,7 +23,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
TestBranchMergeSwitch ();
TestBranchMergeTry ();
TestBranchMergeCatch ();
- TestBranchMergeFinally ();
// The remaining tests illustrate current limitations of the analysis
// that we might be able to lift in the future.
@@ -32,6 +36,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
TestBranchTry ();
TestBranchCatch ();
TestBranchFinally ();
+ TestBranchMergeFinally ();
// These are missing warnings (potential failure at runtime)
TestBackwardsEdgeGoto ();
@@ -41,16 +46,12 @@ namespace Mono.Linker.Tests.Cases.DataFlow
TestNoWarningsInRUCType ();
}
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicFields), new Type[] { typeof (string) },
- messageCode: "IL2072", message: new string[] {
+ [ExpectedWarning ("IL2072",
"Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.GetWithPublicMethods()",
- "type",
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.RequirePublicFields(String)"})]
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicMethods), new Type[] { typeof (string) },
- messageCode: "IL2072", message: new string[] {
+ nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicFields) + "(String)")]
+ [ExpectedWarning ("IL2072",
"Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.GetWithPublicFields()",
- "type",
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.RequirePublicMethods(String)"})]
+ nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicMethods) + "(String)")]
public static void TestBranchMergeGoto ()
{
string str = GetWithPublicMethods ();
@@ -59,40 +60,32 @@ namespace Mono.Linker.Tests.Cases.DataFlow
str = GetWithPublicFields ();
End:
- RequirePublicFields (str); // warns for GetWithPublicMethods
- RequirePublicMethods (str); // warns for GetWithPublicFields
+ str.RequiresPublicFields (); // warns for GetWithPublicMethods
+ str.RequiresPublicMethods (); // warns for GetWithPublicFields
}
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicFields), new Type[] { typeof (string) },
- messageCode: "IL2072", message: new string[] {
+ [ExpectedWarning ("IL2072",
"Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.GetWithPublicMethods()",
- "type",
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.RequirePublicFields(String)" })]
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicMethods), new Type[] { typeof (string) },
- messageCode: "IL2072", message: new string[] {
+ nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicFields) + "(String)")]
+ [ExpectedWarning ("IL2072",
"Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.GetWithPublicFields()",
- "type",
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.RequirePublicMethods(String)" })]
+ nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicMethods) + "(String)")]
public static void TestBranchMergeIf ()
{
string str = GetWithPublicMethods ();
if (String.Empty.Length == 0)
str = GetWithPublicFields ();
- RequirePublicFields (str); // warns for GetWithPublicMethods
- RequirePublicMethods (str); // warns for GetWithPublicFields
+ str.RequiresPublicFields (); // warns for GetWithPublicMethods
+ str.RequiresPublicMethods (); // warns for GetWithPublicFields
}
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicFields), new Type[] { typeof (string) },
- messageCode: "IL2072", message: new string[] {
+ [ExpectedWarning ("IL2072",
"Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.GetWithPublicMethods()",
- "type",
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.RequirePublicFields(String)" })]
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicMethods), new Type[] { typeof (string) },
- messageCode: "IL2072", message: new string[] {
+ nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicFields) + "(String)")]
+ [ExpectedWarning ("IL2072",
"Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.GetWithPublicFields()",
- "type",
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.RequirePublicMethods(String)" })]
+ nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicMethods) + "(String)")]
public static void TestBranchMergeIfElse ()
{
string str = null;
@@ -101,27 +94,21 @@ namespace Mono.Linker.Tests.Cases.DataFlow
} else {
str = GetWithPublicMethods ();
}
- RequirePublicFields (str); // warns for GetWithPublicMethods
- RequirePublicMethods (str); // warns for GetWithPublicFields
+ str.RequiresPublicFields (); // warns for GetWithPublicMethods
+ str.RequiresPublicMethods (); // warns for GetWithPublicFields
}
static int _switchOnField;
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequireNonPublicMethods), new Type[] { typeof (string) },
- messageCode: "IL2072", message: new string[] {
+ [ExpectedWarning ("IL2072",
"Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.GetWithPublicFields()",
- "type",
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.RequireNonPublicMethods(String)" })]
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequireNonPublicMethods), new Type[] { typeof (string) },
- messageCode: "IL2072", message: new string[] {
+ nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresNonPublicMethods) + "(String)")]
+ [ExpectedWarning ("IL2072",
"Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.GetWithPublicMethods()",
- "type",
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.RequireNonPublicMethods(String)" })]
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequireNonPublicMethods), new Type[] { typeof (string) },
- messageCode: "IL2072", message: new string[] {
+ nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresNonPublicMethods) + "(String)")]
+ [ExpectedWarning ("IL2072",
"Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.GetWithPublicConstructors()",
- "type",
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.RequireNonPublicMethods(String)" })]
+ nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresNonPublicMethods) + "(String)")]
public static void TestBranchMergeSwitch ()
{
string str = null;
@@ -139,19 +126,15 @@ namespace Mono.Linker.Tests.Cases.DataFlow
str = GetWithPublicConstructors ();
break;
}
- RequireNonPublicMethods (str); // warns for GetWithPublicFields, GetWithPublicMethods, and GetWithPublicConstructors
+
+ str.RequiresNonPublicMethods (); // warns for GetWithPublicFields, GetWithPublicMethods, and GetWithPublicConstructors
}
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicFields), new Type[] { typeof (string) },
- messageCode: "IL2072", message: new string[] {
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.GetWithPublicMethods()",
- "type",
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.RequirePublicFields(String)" })]
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicMethods), new Type[] { typeof (string) },
- messageCode: "IL2072", message: new string[] {
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.GetWithPublicFields()",
- "type",
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.RequirePublicMethods(String)" })]
+
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicFields) + "(String)",
+ nameof (LocalDataFlow) + "." + nameof (GetWithPublicMethods) + "()")]
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicMethods) + "(String)",
+ nameof (LocalDataFlow) + "." + nameof (GetWithPublicFields) + "()")]
public static void TestBranchMergeTry ()
{
string str = GetWithPublicMethods ();
@@ -162,20 +145,16 @@ namespace Mono.Linker.Tests.Cases.DataFlow
str = GetWithPublicFields ();
} catch {
}
- RequirePublicFields (str); // warns for GetWithPublicMethods
- RequirePublicMethods (str); // warns for GetWithPublicFields
+
+ str.RequiresPublicFields (); // warns for GetWithPublicMethods
+ str.RequiresPublicMethods (); // warns for GetWithPublicFields
}
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicFields), new Type[] { typeof (string) },
- messageCode: "IL2072", message: new string[] {
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.GetWithPublicMethods()",
- "type",
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.RequirePublicFields(String)" })]
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicMethods), new Type[] { typeof (string) },
- messageCode: "IL2072", message: new string[] {
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.GetWithPublicFields()",
- "type",
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.RequirePublicMethods(String)" })]
+
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicFields) + "(String)",
+ nameof (LocalDataFlow) + "." + nameof (GetWithPublicMethods) + "()")]
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicMethods) + "(String)",
+ nameof (LocalDataFlow) + "." + nameof (GetWithPublicFields) + "()")]
public static void TestBranchMergeCatch ()
{
string str = GetWithPublicMethods ();
@@ -185,20 +164,17 @@ namespace Mono.Linker.Tests.Cases.DataFlow
} catch {
str = GetWithPublicFields ();
}
- RequirePublicFields (str); // warns for GetWithPublicMethods
- RequirePublicMethods (str); // warns for GetWithPublicFields
+
+ str.RequiresPublicFields (); // warns for GetWithPublicMethods
+ str.RequiresPublicMethods (); // warns for GetWithPublicFields
}
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicFields), new Type[] { typeof (string) },
- messageCode: "IL2072", message: new string[] {
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.GetWithPublicMethods()",
- "type",
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.RequirePublicFields(String)" })]
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicMethods), new Type[] { typeof (string) },
- messageCode: "IL2072", message: new string[] {
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.GetWithPublicFields()",
- "type",
- "Mono.Linker.Tests.Cases.DataFlow.LocalDataFlow.RequirePublicMethods(String)" })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicMethods) + "(String)",
+ nameof (LocalDataFlow) + "." + nameof (GetWithPublicFields) + "()")]
+ // Linker produces extraneous warnings
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicFields) + "(String)",
+ nameof (LocalDataFlow) + "." + nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Trimmer)]
public static void TestBranchMergeFinally ()
{
string str = GetWithPublicMethods ();
@@ -209,77 +185,93 @@ namespace Mono.Linker.Tests.Cases.DataFlow
} finally {
str = GetWithPublicFields ();
}
- RequirePublicFields (str); // warns for GetWithPublicMethods
- RequirePublicMethods (str); // warns for GetWithPublicFields
+ str.RequiresPublicFields (); // should not warn
+ str.RequiresPublicMethods (); // should warn
}
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicFields), new Type[] { typeof (string) }, messageCode: "IL2072")]
+ // Analyzer gets this right (no warning), but trimmer merges all branches going forward.
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicFields) + "(String)",
+ ProducedBy = ProducedBy.Trimmer)]
public static void TestBranchGoto ()
{
string str = GetWithPublicMethods ();
if (String.Empty.Length == 0)
goto End;
str = GetWithPublicFields ();
- RequirePublicFields (str); // produces a warning
+ str.RequiresPublicFields (); // produces a warning
End:
return;
}
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicFields), new Type[] { typeof (string) }, messageCode: "IL2072")]
+ // Analyzer gets this right (no warning), but trimmer merges all branches going forward.
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicFields),
+ ProducedBy = ProducedBy.Trimmer)]
public static void TestBranchIf ()
{
string str = GetWithPublicMethods ();
if (String.Empty.Length == 0) {
str = GetWithPublicFields (); // dataflow will merge this with the value from the previous basic block
- RequirePublicFields (str); // produces a warning (technically it should not)
+ str.RequiresPublicFields (); // produces a warning (technically it should not)
}
}
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicFields), new Type[] { typeof (string) }, messageCode: "IL2072")]
+ // Analyzer gets this right (no warning), but trimmer merges all branches going forward.
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicFields),
+ ProducedBy = ProducedBy.Trimmer)]
public static void TestBranchIfElse ()
{
string str;
if (String.Empty.Length == 0) {
// because this branch *happens* to come first in IL, we will only see one value
str = GetWithPublicMethods ();
- RequirePublicMethods (str); // this works
+ str.RequiresPublicMethods (); // this works
} else {
// because this branch *happens* to come second in IL, we will see the merged value for str
str = GetWithPublicFields ();
- RequirePublicFields (str); // produces a warning
+ str.RequiresPublicFields (); // produces a warning
}
}
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequireNonPublicMethods), new Type[] { typeof (string) }, messageCode: "IL2072")]
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicMethods), new Type[] { typeof (string) }, messageCode: "IL2072")]
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicMethods), new Type[] { typeof (string) }, messageCode: "IL2072")]
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (string) }, messageCode: "IL2072")]
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (string) }, messageCode: "IL2072")]
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (string) }, messageCode: "IL2072")]
+ // Analyzer gets this right (no warning), but trimmer merges all branches going forward.
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresNonPublicMethods) + "(String)",
+ ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicMethods) + "(String)",
+ ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicMethods) + "(String)",
+ ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicConstructors) + "(String)",
+ ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicConstructors) + "(String)",
+ ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicConstructors) + "(String)",
+ ProducedBy = ProducedBy.Trimmer)]
public static void TestBranchSwitch ()
{
string str = null;
switch (_switchOnField) {
case 0:
str = GetWithPublicFields ();
- RequirePublicFields (str); // success
+ str.RequiresPublicFields (); // success
break;
case 1:
str = GetWithNonPublicMethods ();
- RequireNonPublicMethods (str); // warns for GetWithPublicFields
+ str.RequiresNonPublicMethods (); // warns for GetWithPublicFields
break;
case 2:
str = GetWithPublicMethods ();
- RequirePublicMethods (str); // warns for GetWithPublicFields and GetWithNonPublicMethods
+ str.RequiresPublicMethods (); // warns for GetWithPublicFields and GetWithNonPublicMethods
break;
case 3:
str = GetWithPublicConstructors ();
- RequirePublicConstructors (str); // warns for GetWithPublicFields, GetWithNonPublicMethods, GetWithPublicMethods
+ str.RequiresPublicConstructors (); // warns for GetWithPublicFields, GetWithNonPublicMethods, GetWithPublicMethods
break;
}
}
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicFields), new Type[] { typeof (string) }, messageCode: "IL2072")]
+ // Analyzer gets this right (no warning), but trimmer merges all branches going forward.
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicFields),
+ nameof (LocalDataFlow) + "." + nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Trimmer)]
public static void TestBranchTry ()
{
string str = GetWithPublicMethods ();
@@ -288,12 +280,15 @@ namespace Mono.Linker.Tests.Cases.DataFlow
throw null;
str = GetWithPublicFields ();
- RequirePublicFields (str); // warns for GetWithPublicMethods
+ str.RequiresPublicFields (); // warns for GetWithPublicMethods
} catch {
}
}
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicFields), new Type[] { typeof (string) }, messageCode: "IL2072")]
+ // Analyzer gets this right (no warning), but trimmer merges all branches going forward.
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicFields),
+ nameof (LocalDataFlow) + "." + nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Trimmer)]
public static void TestBranchCatch ()
{
string str = GetWithPublicMethods ();
@@ -302,11 +297,14 @@ namespace Mono.Linker.Tests.Cases.DataFlow
throw null;
} catch {
str = GetWithPublicFields ();
- RequirePublicFields (str); // warns for GetWithPublicMethods
+ str.RequiresPublicFields (); // warns for GetWithPublicMethods
}
}
- [UnrecognizedReflectionAccessPattern (typeof (LocalDataFlow), nameof (RequirePublicFields), new Type[] { typeof (string) }, messageCode: "IL2072")]
+ // Analyzer gets this right (no warning), but trimmer merges all branches going forward.
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicFields),
+ nameof (LocalDataFlow) + "." + nameof (GetWithPublicMethods) + "()",
+ ProducedBy = ProducedBy.Trimmer)]
public static void TestBranchFinally ()
{
string str = GetWithPublicMethods ();
@@ -316,11 +314,14 @@ namespace Mono.Linker.Tests.Cases.DataFlow
} catch {
} finally {
str = GetWithPublicFields ();
- RequirePublicFields (str); // warns for GetWithPublicMethods
+ str.RequiresPublicFields (); // warns for GetWithPublicMethods
}
}
- [RecognizedReflectionAccessPattern]
+ // Analyzer gets this right, but linker doesn't consider backwards branches.
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicMethods) + "(String)",
+ nameof (LocalDataFlow) + "." + nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
public static void TestBackwardsEdgeLoop ()
{
string str = GetWithPublicMethods ();
@@ -330,17 +331,20 @@ namespace Mono.Linker.Tests.Cases.DataFlow
str = GetWithPublicFields (); // dataflow will merge values to track both possible annotation kinds
}
- // RequirePublicMethods (str); // this would produce a warning for the value that comes from GetWithPublicFields, as expected
- RequirePublicMethods (prev); // this produces no warning, even though "prev" will have the value from GetWithPublicFields!
+ // str.RequiresPublicMethods (); // this would produce a warning for the value that comes from GetWithPublicFields, as expected
+ prev.RequiresPublicMethods (); // this produces no warning, even though "prev" will have the value from GetWithPublicFields!
}
- [RecognizedReflectionAccessPattern]
+ // Analyzer gets this right, but linker doesn't consider backwards branches.
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicMethods) + "(String)",
+ nameof (LocalDataFlow) + "." + nameof (GetWithPublicFields) + "()",
+ ProducedBy = ProducedBy.Analyzer)]
public static void TestBackwardsEdgeGoto ()
{
string str = null;
goto ForwardTarget;
BackwardTarget:
- RequirePublicMethods (str); // should warn for the value that comes from GetWithPublicFields, but it doesn't.
+ str.RequiresPublicMethods (); // should warn for the value that comes from GetWithPublicFields, but it doesn't.
return;
ForwardTarget:
@@ -357,7 +361,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
[RequiresUnreferencedCode ("message")]
public static void RUCMethod ()
{
- RequireAll (GetWithPublicMethods ());
+ GetWithPublicMethods ().RequiresAll ();
}
[ExpectedWarning ("IL2026", nameof (RUCType) + "." + nameof (RUCType), "message")]
@@ -375,49 +379,20 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
public static void StaticMethod ()
{
- RequireAll (GetWithPublicMethods ());
+ GetWithPublicMethods ().RequiresAll ();
}
public void InstanceMethod ()
{
- RequireAll (GetWithPublicMethods ());
+ GetWithPublicMethods ().RequiresAll ();
}
public virtual void VirtualMethod ()
{
- RequireAll (GetWithPublicMethods ());
+ GetWithPublicMethods ().RequiresAll ();
}
}
- public static void RequireAll (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
- string type)
- {
- }
-
- public static void RequirePublicFields (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)]
- string type)
- {
- }
-
- public static void RequireNonPublicMethods (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicMethods)]
- string type)
- {
- }
- public static void RequirePublicMethods (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
- string type)
- {
- }
-
- public static void RequirePublicConstructors (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
- string type)
- {
- }
-
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)]
public static string GetWithPublicFields ()
{
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/LocalDataFlowKeptMembers.cs b/test/Mono.Linker.Tests.Cases/DataFlow/LocalDataFlowKeptMembers.cs
index 4c3484013..8e95a6ebc 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/LocalDataFlowKeptMembers.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/LocalDataFlowKeptMembers.cs
@@ -4,6 +4,7 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions;
namespace Mono.Linker.Tests.Cases.DataFlow
{
+ [ExpectedNoWarnings]
public class LocalDataFlowKeptMembers
{
public static void Main ()
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/MemberTypes.cs b/test/Mono.Linker.Tests.Cases/DataFlow/MemberTypes.cs
index af1a2c7ee..94b565d39 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/MemberTypes.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/MemberTypes.cs
@@ -12,8 +12,66 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.DataFlow
{
[SetupCompileArgument ("/optimize+")]
+ [ExpectedNoWarnings]
public class MemberTypes
{
+ // Some of the types below declare delegates and will mark all members on them, this includes the Delegate .ctor(object, string) which has RUC and other members
+ [ExpectedWarning ("IL2026", nameof (Delegate) + ".Delegate", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (Delegate) + ".Delegate", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (Delegate) + ".Delegate", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (Delegate) + ".Delegate", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (Delegate) + ".Delegate", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (MulticastDelegate) + ".MulticastDelegate", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (MulticastDelegate) + ".MulticastDelegate", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (MulticastDelegate) + ".MulticastDelegate", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (MulticastDelegate) + ".MulticastDelegate", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", nameof (MulticastDelegate) + ".MulticastDelegate", ProducedBy = ProducedBy.Trimmer)]
+ // Some of the types below declare delegates and will mark all members on them, this includes the Delegate .ctor(Type, string) which has DAM annotations and other members
+ [ExpectedWarning ("IL2111", nameof (Delegate) + ".Delegate", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate) + ".Delegate", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate) + ".Delegate", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate) + ".Delegate", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate) + ".Delegate", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate), ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (MulticastDelegate) + ".MulticastDelegate", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (MulticastDelegate) + ".MulticastDelegate", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (MulticastDelegate) + ".MulticastDelegate", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (MulticastDelegate) + ".MulticastDelegate", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (MulticastDelegate) + ".MulticastDelegate", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate) + ".BindToMethodName", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate) + ".BindToMethodName", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate) + ".BindToMethodName", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate) + ".BindToMethodName", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2111", nameof (Delegate) + ".BindToMethodName", ProducedBy = ProducedBy.Trimmer)]
public static void Main ()
{
RequirePublicParameterlessConstructor (typeof (PublicParameterlessConstructorType));
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/MemberTypesAllOnCopyAssembly.cs b/test/Mono.Linker.Tests.Cases/DataFlow/MemberTypesAllOnCopyAssembly.cs
index 8331edaea..dd9bd5cfc 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/MemberTypesAllOnCopyAssembly.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/MemberTypesAllOnCopyAssembly.cs
@@ -13,6 +13,8 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.DataFlow
{
+ [ExpectedNoWarnings]
+
[SetupCompileBefore ("base.dll", new[] { "Dependencies/MemberTypesAllBaseTypeAssembly.cs" })]
[KeptAssembly ("base.dll")]
[SetupLinkerAction ("link", "base")]
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs
index df6e2cd1e..324e75cf2 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs
@@ -6,13 +6,15 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Helpers;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.DataFlow
{
// Note: this test's goal is to validate that the product correctly reports unrecognized patterns
- // - so the main validation is done by the UnrecognizedReflectionAccessPattern attributes.
+ // - so the main validation is done by the ExpectedWarning attributes.
[SkipKeptItemsValidation]
+ [ExpectedNoWarnings]
[SetupLinkerArgument ("--keep-metadata", "parametername")]
public class MethodParametersDataFlow
{
@@ -41,46 +43,45 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
// Validate the error message when annotated parameter is passed to another annotated parameter
- [UnrecognizedReflectionAccessPattern (typeof (MethodParametersDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) },
- messageCode: "IL2067", message: new string[] { "sourceType", "PublicParameterlessConstructorParameter(Type)", "type", "RequirePublicConstructors(Type)" })]
- [UnrecognizedReflectionAccessPattern (typeof (MethodParametersDataFlow), nameof (RequireNonPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2067")]
+ [ExpectedWarning ("IL2067", "'sourceType'", "PublicParameterlessConstructorParameter(Type)", "'type'", "RequiresPublicConstructors(Type)")]
+ [ExpectedWarning ("IL2067", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors))]
private static void PublicParameterlessConstructorParameter (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
Type sourceType)
{
- RequirePublicParameterlessConstructor (sourceType);
- RequirePublicConstructors (sourceType);
- RequireNonPublicConstructors (sourceType);
+ sourceType.RequiresPublicParameterlessConstructor ();
+ sourceType.RequiresPublicConstructors ();
+ sourceType.RequiresNonPublicConstructors ();
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodParametersDataFlow), nameof (RequireNonPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2067")]
+ [ExpectedWarning ("IL2067", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors))]
private static void PublicConstructorsParameter (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
Type type)
{
- RequirePublicParameterlessConstructor (type);
- RequirePublicConstructors (type);
- RequireNonPublicConstructors (type);
+ type.RequiresPublicParameterlessConstructor ();
+ type.RequiresPublicConstructors ();
+ type.RequiresNonPublicConstructors ();
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodParametersDataFlow), nameof (RequirePublicParameterlessConstructor), new Type[] { typeof (Type) }, messageCode: "IL2067")]
- [UnrecognizedReflectionAccessPattern (typeof (MethodParametersDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2067")]
+ [ExpectedWarning ("IL2067", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicParameterlessConstructor))]
+ [ExpectedWarning ("IL2067", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors))]
private static void NonPublicConstructorsParameter (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors)]
Type type)
{
- RequirePublicParameterlessConstructor (type);
- RequirePublicConstructors (type);
- RequireNonPublicConstructors (type);
+ type.RequiresPublicParameterlessConstructor ();
+ type.RequiresPublicConstructors ();
+ type.RequiresNonPublicConstructors ();
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodParametersDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2067")]
+ [ExpectedWarning ("IL2067", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors))]
private void InstanceMethod (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
Type type)
{
- RequirePublicParameterlessConstructor (type);
- RequirePublicConstructors (type);
+ type.RequiresPublicParameterlessConstructor ();
+ type.RequiresPublicConstructors ();
}
[ExpectedWarning ("IL2072", "'type'", "argument", nameof (WriteToParameterOnInstanceMethod) + "(Type)", nameof (ReturnThingsWithPublicParameterlessConstructor))]
@@ -99,7 +100,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
type = ReturnThingsWithPublicParameterlessConstructor ();
}
- [ExpectedWarning ("IL2072", "'type'", "argument", nameof (LongWriteToParameterOnInstanceMethod) + "(Int32,Int32,Int32,Int32,Type)", nameof (ReturnThingsWithPublicParameterlessConstructor))]
+ [ExpectedWarning ("IL2072", "'type'", "argument", nameof (LongWriteToParameterOnInstanceMethod) + "(Int32, Int32, Int32, Int32, Type)", nameof (ReturnThingsWithPublicParameterlessConstructor))]
private void LongWriteToParameterOnInstanceMethod (
int a, int b, int c, int d,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors)]
@@ -108,7 +109,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
type = ReturnThingsWithPublicParameterlessConstructor ();
}
- [ExpectedWarning ("IL2072", "'type'", "argument", nameof (LongWriteToParameterOnStaticMethod) + "(Int32,Int32,Int32,Int32,Type)", nameof (ReturnThingsWithPublicParameterlessConstructor))]
+ [ExpectedWarning ("IL2072", "'type'", "argument", nameof (LongWriteToParameterOnStaticMethod) + "(Int32, Int32, Int32, Int32, Type)", nameof (ReturnThingsWithPublicParameterlessConstructor))]
private static void LongWriteToParameterOnStaticMethod (
int a, int b, int c, int d,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors)]
@@ -123,20 +124,24 @@ namespace Mono.Linker.Tests.Cases.DataFlow
return null;
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodParametersDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2067")]
+ [ExpectedWarning ("IL2067", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors))]
private void TwoAnnotatedParameters (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
Type type,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
Type type2)
{
- RequirePublicParameterlessConstructor (type);
- RequirePublicParameterlessConstructor (type2);
- RequirePublicConstructors (type);
- RequirePublicConstructors (type2);
+ type.RequiresPublicParameterlessConstructor ();
+ type2.RequiresPublicParameterlessConstructor ();
+ type.RequiresPublicConstructors ();
+ type2.RequiresPublicConstructors ();
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodParametersDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2067")]
+ // TODO: https://github.com/dotnet/linker/issues/2273
+ // (Dataflow analysis is not supported by the analyzer yet)
+ [ExpectedWarning ("IL2067",
+ nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors) + "(Type)",
+ "'type'")]
private void TwoAnnotatedParametersIntoOneValue (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
Type type,
@@ -144,80 +149,57 @@ namespace Mono.Linker.Tests.Cases.DataFlow
Type type2)
{
Type t = type == null ? type : type2;
- RequirePublicParameterlessConstructor (t);
- RequirePublicConstructors (t);
+ t.RequiresPublicParameterlessConstructor ();
+ t.RequiresPublicConstructors ();
}
// Validate the error message for the case of unannotated method return value passed to an annotated parameter.
- [UnrecognizedReflectionAccessPattern (typeof (MethodParametersDataFlow), nameof (RequirePublicParameterlessConstructor), new Type[] { typeof (Type) },
- messageCode: "IL2067", message: new string[] { "type", "NoAnnotation(Type)", "type", "RequirePublicParameterlessConstructor(Type)" })]
+ [ExpectedWarning ("IL2067", "'type'", "NoAnnotation(Type)", "'type'", "RequiresPublicParameterlessConstructor(Type)")]
private void NoAnnotation (Type type)
{
- RequirePublicParameterlessConstructor (type);
+ type.RequiresPublicParameterlessConstructor ();
}
// Validate error message when untracable value is passed to an annotated parameter.
- [UnrecognizedReflectionAccessPattern (typeof (MethodParametersDataFlow), nameof (RequirePublicParameterlessConstructor), new Type[] { typeof (Type) },
- messageCode: "IL2062", message: new string[] { "type", "RequirePublicParameterlessConstructor" })]
+ [ExpectedWarning ("IL2062",
+ nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicParameterlessConstructor) + "(Type)",
+ "'type'",
+ ProducedBy = ProducedBy.Trimmer)]
private void UnknownValue ()
{
var array = new object[1];
array[0] = this.GetType ();
MakeArrayValuesUnknown (array);
- RequirePublicParameterlessConstructor ((Type) array[0]);
+ ((Type) array[0]).RequiresPublicParameterlessConstructor ();
static void MakeArrayValuesUnknown (object[] array)
{
}
}
- [RecognizedReflectionAccessPattern]
private void AnnotatedValueToUnAnnotatedParameter (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
Type type)
{
- RequireNothing (type);
+ type.RequiresNone ();
}
- [RecognizedReflectionAccessPattern]
private void UnknownValueToUnAnnotatedParameter ()
{
- RequireNothing (this.GetType ());
+ this.GetType ().RequiresNone ();
}
- [RecognizedReflectionAccessPattern]
private void UnknownValueToUnAnnotatedParameterOnInterestingMethod ()
{
RequirePublicParameterlessConstructorAndNothing (typeof (TestType), this.GetType ());
}
- [ExpectedWarning ("IL2098", "p1", nameof (UnsupportedParameterType))]
+ // TODO: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2098", "p1", nameof (UnsupportedParameterType), ProducedBy = ProducedBy.Trimmer)]
private void UnsupportedParameterType ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] object p1)
{
}
- private static void RequirePublicParameterlessConstructor (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
- Type type)
- {
- }
-
- private static void RequirePublicConstructors (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
- Type type)
- {
- }
-
- private static void RequireNonPublicConstructors (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors)]
- Type type)
- {
- }
-
- private static void RequireNothing (Type type)
- {
- }
-
private static void RequirePublicParameterlessConstructorAndNothing (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
Type type,
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/MethodReturnParameterDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/MethodReturnParameterDataFlow.cs
index 28735fd9d..1a2ee9aa3 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/MethodReturnParameterDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/MethodReturnParameterDataFlow.cs
@@ -12,7 +12,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.DataFlow
{
// Note: this test's goal is to validate that the product correctly reports unrecognized patterns
- // - so the main validation is done by the UnrecognizedReflectionAccessPattern attributes.
+ // - so the main validation is done by the ExpectedWarning attributes.
[SkipKeptItemsValidation]
[ExpectedNoWarnings]
public class MethodReturnParameterDataFlow
@@ -46,8 +46,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
return typeof (TestType);
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodReturnParameterDataFlow), nameof (ReturnPublicParameterlessConstructor),
- new Type[] { typeof (Type), typeof (Type), typeof (Type) }, returnType: typeof (Type), messageCode: "IL2068")]
+ [ExpectedWarning ("IL2068", nameof (ReturnPublicParameterlessConstructor))]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
Type ReturnPublicParameterlessConstructor (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
@@ -71,41 +70,35 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodReturnParameterDataFlow), nameof (ReturnPublicParameterlessConstructorFromUnknownType),
- new Type[] { typeof (Type) }, returnType: typeof (Type), messageCode: "IL2068")]
+ [ExpectedWarning ("IL2068", nameof (ReturnPublicParameterlessConstructorFromUnknownType))]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
Type ReturnPublicParameterlessConstructorFromUnknownType (Type unknownType)
{
return unknownType;
}
- [RecognizedReflectionAccessPattern]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
Type ReturnPublicParameterlessConstructorFromConstant ()
{
return typeof (TestType);
}
- [RecognizedReflectionAccessPattern]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
Type ReturnPublicParameterlessConstructorFromNull ()
{
return null;
}
- [RecognizedReflectionAccessPattern]
Type ReturnTypeWithNoRequirements ()
{
return null;
}
// Validate error message when insufficiently annotated value is returned from a method
- [UnrecognizedReflectionAccessPattern (typeof (MethodReturnParameterDataFlow), nameof (ReturnPublicConstructorsFailure),
- new Type[] { typeof (Type) }, returnType: typeof (Type),
- messageCode: "IL2068", message: new string[] {
+ [ExpectedWarning ("IL2068",
"publicParameterlessConstructorType",
"MethodReturnParameterDataFlow.ReturnPublicConstructorsFailure",
- "MethodReturnParameterDataFlow.ReturnPublicConstructorsFailure" })]
+ "MethodReturnParameterDataFlow.ReturnPublicConstructorsFailure")]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
Type ReturnPublicConstructorsFailure (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
@@ -114,8 +107,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
return publicParameterlessConstructorType;
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodReturnParameterDataFlow), nameof (ReturnNonPublicConstructorsFailure),
- new Type[] { typeof (Type) }, returnType: typeof (Type), messageCode: "IL2068")]
+ [ExpectedWarning ("IL2068", nameof (ReturnNonPublicConstructorsFailure))]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicConstructors)]
Type ReturnNonPublicConstructorsFailure (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
@@ -124,9 +116,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow
return publicConstructorsType;
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodReturnParameterDataFlow), nameof (ReturnUnknownValue),
- new Type[] { }, returnType: typeof (Type),
- messageCode: "IL2063", message: new string[] { nameof (ReturnUnknownValue) })]
+ // TODO: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2063",
+ nameof (MethodReturnParameterDataFlow) + "." + nameof (ReturnUnknownValue) + "()",
+ ProducedBy = ProducedBy.Trimmer)]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
Type ReturnUnknownValue ()
{
@@ -140,8 +133,12 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")]
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072",
+ nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors) + "(Type)",
+ nameof (MethodReturnParameterDataFlow) + "." + nameof (ReturnPublicParameterlessConstructor) + "(Type, Type, Type)")]
+ [ExpectedWarning ("IL2072",
+ nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors) + "(Type)",
+ nameof (MethodReturnParameterDataFlow) + "." + nameof (ReturnPublicParameterlessConstructor) + "(Type, Type, Type)")]
void PropagateReturnPublicParameterlessConstructor ()
{
Type t = ReturnPublicParameterlessConstructor (typeof (TestType), typeof (TestType), typeof (TestType));
@@ -151,8 +148,12 @@ namespace Mono.Linker.Tests.Cases.DataFlow
t.RequiresNone ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")]
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072",
+ nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors) + "(Type)",
+ nameof (MethodReturnParameterDataFlow) + "." + nameof (ReturnPublicParameterlessConstructorFromConstant) + "()")]
+ [ExpectedWarning ("IL2072",
+ nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors) + "(Type)",
+ nameof (MethodReturnParameterDataFlow) + "." + nameof (ReturnPublicParameterlessConstructorFromConstant) + "()")]
void PropagateReturnPublicParameterlessConstructorFromConstant ()
{
Type t = ReturnPublicParameterlessConstructorFromConstant ();
@@ -162,11 +163,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow
t.RequiresNone ();
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodReturnParameterDataFlow), nameof (PropagateReturnToReturn), new Type[] { typeof (int) }, returnType: typeof (Type),
- messageCode: "IL2073", message: new string[] {
+ [ExpectedWarning ("IL2073",
nameof (ReturnTypeWithNoRequirements),
- nameof (PropagateReturnToReturn)
- })]
+ nameof (PropagateReturnToReturn))]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
Type PropagateReturnToReturn (int n)
{
@@ -180,17 +179,14 @@ namespace Mono.Linker.Tests.Cases.DataFlow
return null;
}
- // https://github.com/dotnet/linker/issues/2025
- // Ideally this should not warn
- [UnrecognizedReflectionAccessPattern (typeof (MethodReturnParameterDataFlow), nameof (ReturnWithRequirementsAlwaysThrows), new Type[] { }, returnType: typeof (Type),
- messageCode: "IL2063")]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
Type ReturnWithRequirementsAlwaysThrows ()
{
throw new NotImplementedException ();
}
- [ExpectedWarning ("IL2106", nameof (UnsupportedReturnType))]
+ // TODO: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2106", nameof (UnsupportedReturnType), ProducedBy = ProducedBy.Trimmer)]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
static object UnsupportedReturnType () => null;
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs
index 5ca8b3181..6a7e8321a 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
@@ -14,6 +14,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
[SkipKeptItemsValidation]
[SandboxDependency ("Dependencies/TestSystemTypeBase.cs")]
+ [ExpectedNoWarnings]
public class MethodThisDataFlow
{
public static void Main ()
@@ -32,11 +33,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow
TestFromGenericParameterToThis<MethodThisDataFlow> ();
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodThisDataFlowTypeTest), nameof (MethodThisDataFlowTypeTest.RequireThisPublicMethods), new Type[] { },
- messageCode: "IL2075", message: new string[] {
+ [ExpectedWarning ("IL2075",
"Mono.Linker.Tests.Cases.DataFlow.MethodThisDataFlow.GetWithNonPublicMethods()",
- "System.MethodThisDataFlowTypeTest.RequireThisPublicMethods()" })]
- [UnrecognizedReflectionAccessPattern (typeof (MethodThisDataFlowTypeTest), nameof (MethodThisDataFlowTypeTest.RequireThisNonPublicMethods), new Type[] { }, messageCode: "IL2075")]
+ "System.MethodThisDataFlowTypeTest.RequireThisPublicMethods()")]
+ [ExpectedWarning ("IL2075", nameof (MethodThisDataFlowTypeTest.RequireThisNonPublicMethods))]
static void PropagateToThis ()
{
GetWithPublicMethods ().RequireThisPublicMethods ();
@@ -46,11 +46,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow
GetWithNonPublicMethods ().RequireThisNonPublicMethods ();
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodThisDataFlowTypeTest), nameof (MethodThisDataFlowTypeTest.PropertyRequireThisPublicMethods) + ".get", new Type[] { },
- messageCode: "IL2075", message: new string[] {
+ [ExpectedWarning ("IL2075",
"Mono.Linker.Tests.Cases.DataFlow.MethodThisDataFlow.GetWithNonPublicMethods()",
- "System.MethodThisDataFlowTypeTest.PropertyRequireThisPublicMethods.get" })]
- [UnrecognizedReflectionAccessPattern (typeof (MethodThisDataFlowTypeTest), nameof (MethodThisDataFlowTypeTest.PropertyRequireThisNonPublicMethods) + ".get", new Type[] { }, messageCode: "IL2075")]
+ "System.MethodThisDataFlowTypeTest.PropertyRequireThisPublicMethods.get")]
+ [ExpectedWarning ("IL2075", nameof (MethodThisDataFlowTypeTest.PropertyRequireThisNonPublicMethods) + ".get")]
static void PropagateToThisWithGetters ()
{
_ = GetWithPublicMethods ().PropertyRequireThisPublicMethods;
@@ -60,11 +59,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow
_ = GetWithNonPublicMethods ().PropertyRequireThisNonPublicMethods;
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodThisDataFlowTypeTest), nameof (MethodThisDataFlowTypeTest.PropertyRequireThisPublicMethods) + ".set", new Type[] { typeof (Object) },
- messageCode: "IL2075", message: new string[] {
+ [ExpectedWarning ("IL2075",
"Mono.Linker.Tests.Cases.DataFlow.MethodThisDataFlow.GetWithNonPublicMethods()",
- "System.MethodThisDataFlowTypeTest.PropertyRequireThisPublicMethods.set" })]
- [UnrecognizedReflectionAccessPattern (typeof (MethodThisDataFlowTypeTest), nameof (MethodThisDataFlowTypeTest.PropertyRequireThisNonPublicMethods) + ".set", new Type[] { typeof (Object) }, messageCode: "IL2075")]
+ "System.MethodThisDataFlowTypeTest.PropertyRequireThisPublicMethods.set")]
+ [ExpectedWarning ("IL2075", nameof (MethodThisDataFlowTypeTest.PropertyRequireThisNonPublicMethods) + ".set")]
static void PropagateToThisWithSetters ()
{
GetWithPublicMethods ().PropertyRequireThisPublicMethods = null;
@@ -85,7 +83,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
return null;
}
- [RecognizedReflectionAccessPattern]
static void TestAnnotationOnNonTypeMethod ()
{
var t = new NonTypeType ();
@@ -93,8 +90,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow
NonTypeType.StaticMethod ();
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodThisDataFlowTypeTest), nameof (MethodThisDataFlowTypeTest.RequireThisNonPublicMethods), new Type[] { },
- messageCode: "IL2065", message: new string[] { nameof (MethodThisDataFlowTypeTest.RequireThisNonPublicMethods) })]
+ // Analyer doesn't warn about unknown values flowing into annotated locations
+ // https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2065", nameof (MethodThisDataFlowTypeTest) + "." + nameof (MethodThisDataFlowTypeTest.RequireThisNonPublicMethods), "'this'",
+ ProducedBy = ProducedBy.Trimmer)]
static void TestUnknownThis ()
{
var array = new object[1];
@@ -107,8 +106,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodThisDataFlowTypeTest), nameof (MethodThisDataFlowTypeTest.RequireThisPublicMethods), new Type[] { },
- messageCode: "IL2070", message: new string[] { "sourceType", nameof (TestFromParameterToThis), nameof (MethodThisDataFlowTypeTest.RequireThisPublicMethods) })]
+ [ExpectedWarning ("IL2070", "sourceType", nameof (TestFromParameterToThis), nameof (MethodThisDataFlowTypeTest.RequireThisPublicMethods))]
static void TestFromParameterToThis (MethodThisDataFlowTypeTest sourceType)
{
sourceType.RequireThisPublicMethods ();
@@ -116,19 +114,16 @@ namespace Mono.Linker.Tests.Cases.DataFlow
static MethodThisDataFlowTypeTest _typeField;
- [UnrecognizedReflectionAccessPattern (typeof (MethodThisDataFlowTypeTest), nameof (MethodThisDataFlowTypeTest.RequireThisPublicMethods), new Type[] { },
- messageCode: "IL2080", message: new string[] { nameof (_typeField), nameof (MethodThisDataFlowTypeTest.RequireThisPublicMethods) })]
+ [ExpectedWarning ("IL2080", nameof (_typeField), nameof (MethodThisDataFlowTypeTest.RequireThisPublicMethods))]
static void TestFromFieldToThis ()
{
_typeField.RequireThisPublicMethods ();
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodThisDataFlowTypeTest), nameof (MethodThisDataFlowTypeTest.RequireThisPublicMethods), new Type[] { },
- messageCode: "IL2090", message: new string[] {
+ [ExpectedWarning ("IL2090",
"TSource",
"TestFromGenericParameterToThis<TSource>",
- nameof (MethodThisDataFlowTypeTest.RequireThisPublicMethods)
- })]
+ nameof (MethodThisDataFlowTypeTest.RequireThisPublicMethods))]
static void TestFromGenericParameterToThis<TSource> ()
{
((MethodThisDataFlowTypeTest) typeof (TSource)).RequireThisPublicMethods ();
@@ -143,14 +138,18 @@ namespace Mono.Linker.Tests.Cases.DataFlow
class NonTypeType
{
- [ExpectedWarning ("IL2041")]
+ // Analyzer doesn't warn about annotations on unsupported types:
+ // https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2041", ProducedBy = ProducedBy.Trimmer)]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
public MethodInfo GetMethod (string name)
{
return null;
}
- [ExpectedWarning ("IL2041")]
+ // Analyzer doesn't warn about annotations on unsupported types:
+ // https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2041", ProducedBy = ProducedBy.Trimmer)]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
public static void StaticMethod ()
{
@@ -164,10 +163,9 @@ namespace System
class MethodThisDataFlowTypeTest : TestSystemTypeBase
{
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
- [UnrecognizedReflectionAccessPattern (typeof (MethodThisDataFlowTypeTest), nameof (RequireNonPublicMethods), new Type[] { typeof (Type) },
- messageCode: "IL2082", message: new string[] {
- "'type' argument ", "in call to 'System.MethodThisDataFlowTypeTest.RequireNonPublicMethods(Type)'",
- "implicit 'this' argument of method 'System.MethodThisDataFlowTypeTest.RequireThisPublicMethods()'" })]
+ [ExpectedWarning ("IL2082", nameof (MethodThisDataFlowTypeTest) + "." + nameof (RequireNonPublicMethods) + "(Type)",
+ "'type' argument ", "in call to 'System.MethodThisDataFlowTypeTest.RequireNonPublicMethods(Type)'",
+ "implicit 'this' argument of method 'System.MethodThisDataFlowTypeTest.RequireThisPublicMethods()'")]
public void RequireThisPublicMethods ()
{
RequirePublicMethods (this);
@@ -175,19 +173,16 @@ namespace System
}
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicMethods)]
- [UnrecognizedReflectionAccessPattern (typeof (MethodThisDataFlowTypeTest), nameof (RequirePublicMethods), new Type[] { typeof (Type) },
- messageCode: "IL2082")]
+ [ExpectedWarning ("IL2082", nameof (MethodThisDataFlowTypeTest) + "." + nameof (RequirePublicMethods) + "(Type)")]
public void RequireThisNonPublicMethods ()
{
RequirePublicMethods (this);
RequireNonPublicMethods (this);
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodThisDataFlowTypeTest), nameof (PropagateToReturn), new Type[] { }, returnType: typeof (Type),
- messageCode: "IL2083", message: new string[] {
- nameof(PropagateToReturn),
- nameof(PropagateToReturn)
- })]
+ [ExpectedWarning ("IL2083",
+ nameof (PropagateToReturn),
+ nameof (PropagateToReturn))]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
public Type PropagateToReturn ()
@@ -198,22 +193,17 @@ namespace System
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
Type _requiresPublicConstructors;
- [UnrecognizedReflectionAccessPattern (typeof (MethodThisDataFlowTypeTest), nameof (_requiresPublicConstructors),
- messageCode: "IL2084", message: new string[] {
- nameof (PropagateToField),
- nameof (_requiresPublicConstructors)
- })]
+ [ExpectedWarning ("IL2084", nameof (MethodThisDataFlowTypeTest) + "." + nameof (_requiresPublicConstructors),
+ nameof (PropagateToField))]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
public void PropagateToField ()
{
_requiresPublicConstructors = this;
}
- [UnrecognizedReflectionAccessPattern (typeof (MethodThisDataFlowTypeTest), nameof (RequireThisNonPublicMethods), new Type[] { },
- messageCode: "IL2085", message: new string[] {
+ [ExpectedWarning ("IL2085",
nameof (PropagateToThis),
- nameof (RequireThisNonPublicMethods)
- })]
+ nameof (RequireThisNonPublicMethods))]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
public void PropagateToThis ()
{
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs
index d1f6d57eb..4f2f329c9 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs
@@ -10,8 +10,9 @@ using Mono.Linker.Tests.Cases.Expectations.Helpers;
namespace Mono.Linker.Tests.Cases.DataFlow
{
// Note: this test's goal is to validate that the product correctly reports unrecognized patterns
- // - so the main validation is done by the UnrecognizedReflectionAccessPattern attributes.
+ // - so the main validation is done by the ExpectedWarning attributes.
[SkipKeptItemsValidation]
+ [ExpectedNoWarnings]
public class PropertyDataFlow
{
public static void Main ()
@@ -42,11 +43,13 @@ namespace Mono.Linker.Tests.Cases.DataFlow
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
static Type StaticPropertyWithPublicConstructor { get; set; }
- [ExpectedWarning ("IL2099", nameof (PropertyWithUnsupportedType))]
+ // Analyzer doesn't warn about annotations on unsupported types
+ // https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2099", nameof (PropertyWithUnsupportedType), ProducedBy = ProducedBy.Trimmer)]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)]
static object PropertyWithUnsupportedType { get; set; }
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors))]
private void ReadFromInstanceProperty ()
{
PropertyWithPublicConstructor.RequiresPublicParameterlessConstructor ();
@@ -55,7 +58,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
PropertyWithPublicConstructor.RequiresNone ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors))]
private void ReadFromStaticProperty ()
{
StaticPropertyWithPublicConstructor.RequiresPublicParameterlessConstructor ();
@@ -64,9 +67,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow
StaticPropertyWithPublicConstructor.RequiresNone ();
}
- [UnrecognizedReflectionAccessPattern (typeof (PropertyDataFlow), nameof (PropertyWithPublicConstructor) + ".set", new Type[] { typeof (Type) }, messageCode: "IL2072")]
- [UnrecognizedReflectionAccessPattern (typeof (PropertyDataFlow), nameof (PropertyWithPublicConstructor) + ".set", new Type[] { typeof (Type) }, messageCode: "IL2072")]
- [UnrecognizedReflectionAccessPattern (typeof (PropertyDataFlow), nameof (PropertyWithPublicConstructor) + ".set", new Type[] { typeof (Type) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (PropertyDataFlow) + "." + nameof (PropertyWithPublicConstructor) + ".set", nameof (GetTypeWithPublicParameterlessConstructor))]
+ [ExpectedWarning ("IL2072", nameof (PropertyDataFlow) + "." + nameof (PropertyWithPublicConstructor) + ".set", nameof (GetTypeWithNonPublicConstructors))]
+ [ExpectedWarning ("IL2072", nameof (PropertyDataFlow) + "." + nameof (PropertyWithPublicConstructor) + ".set", nameof (GetUnkownType))]
private void WriteToInstanceProperty ()
{
PropertyWithPublicConstructor = GetTypeWithPublicParameterlessConstructor ();
@@ -75,9 +78,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow
PropertyWithPublicConstructor = GetUnkownType ();
}
- [UnrecognizedReflectionAccessPattern (typeof (PropertyDataFlow), nameof (StaticPropertyWithPublicConstructor) + ".set", new Type[] { typeof (Type) }, messageCode: "IL2072")]
- [UnrecognizedReflectionAccessPattern (typeof (PropertyDataFlow), nameof (StaticPropertyWithPublicConstructor) + ".set", new Type[] { typeof (Type) }, messageCode: "IL2072")]
- [UnrecognizedReflectionAccessPattern (typeof (PropertyDataFlow), nameof (StaticPropertyWithPublicConstructor) + ".set", new Type[] { typeof (Type) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (PropertyDataFlow) + "." + nameof (StaticPropertyWithPublicConstructor) + ".set", nameof (GetTypeWithPublicParameterlessConstructor))]
+ [ExpectedWarning ("IL2072", nameof (PropertyDataFlow) + "." + nameof (StaticPropertyWithPublicConstructor) + ".set", nameof (GetTypeWithNonPublicConstructors))]
+ [ExpectedWarning ("IL2072", nameof (PropertyDataFlow) + "." + nameof (StaticPropertyWithPublicConstructor) + ".set", nameof (GetUnkownType))]
private void WriteToStaticProperty ()
{
StaticPropertyWithPublicConstructor = GetTypeWithPublicParameterlessConstructor ();
@@ -90,13 +93,11 @@ namespace Mono.Linker.Tests.Cases.DataFlow
Type _fieldWithPublicConstructors;
Type PropertyPublicConstructorsWithExplicitAccessors {
- [RecognizedReflectionAccessPattern]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
get {
return _fieldWithPublicConstructors;
}
- [RecognizedReflectionAccessPattern]
[param: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
set {
_fieldWithPublicConstructors = value;
@@ -104,14 +105,14 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
Type PropertyPublicParameterlessConstructorWithExplicitAccessors {
- [RecognizedReflectionAccessPattern]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
get {
return _fieldWithPublicConstructors;
}
- [UnrecognizedReflectionAccessPattern (typeof (PropertyDataFlow), nameof (_fieldWithPublicConstructors),
- messageCode: "IL2069", message: new string[] { "value", nameof (PropertyPublicParameterlessConstructorWithExplicitAccessors) + ".set", nameof (_fieldWithPublicConstructors) })]
+ [ExpectedWarning ("IL2069", nameof (PropertyDataFlow) + "." + nameof (_fieldWithPublicConstructors),
+ "'value'",
+ nameof (PropertyPublicParameterlessConstructorWithExplicitAccessors) + ".set")]
[param: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
set {
_fieldWithPublicConstructors = value;
@@ -119,17 +120,16 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
Type PropertyNonPublicConstructorsWithExplicitAccessors {
- [UnrecognizedReflectionAccessPattern (typeof (PropertyDataFlow), nameof (PropertyNonPublicConstructorsWithExplicitAccessors) + ".get",
- new Type[] { }, returnType: typeof (Type), messageCode: "IL2078", message: new string[] {
- nameof (_fieldWithPublicConstructors),
- nameof (PropertyNonPublicConstructorsWithExplicitAccessors) + ".get"
- })]
+ [ExpectedWarning ("IL2078", nameof (PropertyDataFlow) + "." + nameof (PropertyNonPublicConstructorsWithExplicitAccessors) + ".get",
+ nameof (_fieldWithPublicConstructors))]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicConstructors)]
get {
return _fieldWithPublicConstructors;
}
- [UnrecognizedReflectionAccessPattern (typeof (PropertyDataFlow), nameof (_fieldWithPublicConstructors), messageCode: "IL2069")]
+ [ExpectedWarning ("IL2069", nameof (PropertyDataFlow) + "." + nameof (_fieldWithPublicConstructors),
+ "'value'",
+ nameof (PropertyNonPublicConstructorsWithExplicitAccessors) + ".set")]
[param: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicConstructors)]
set {
_fieldWithPublicConstructors = value;
@@ -145,6 +145,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
instance.TestInstancePropertyWithStaticField ();
instance.TestPropertyWithDifferentBackingFields ();
instance.TestPropertyWithExistingAttributes ();
+ instance.TestPropertyWithConflictingAttributes ();
+ instance.TestPropertyWithConflictingNoneAttributes ();
instance.TestPropertyWithIndexerWithMatchingAnnotations (null);
instance.TestPropertyWithIndexerWithoutMatchingAnnotations (null);
}
@@ -152,7 +154,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
class TestAutomaticPropagationType
{
// Fully implicit property should work
- [UnrecognizedReflectionAccessPattern (typeof (TestAutomaticPropagationType), nameof (ImplicitProperty) + ".set", new Type[] { typeof (Type) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (TestAutomaticPropagationType) + "." + nameof (ImplicitProperty) + ".set")]
public void TestImplicitProperty ()
{
ImplicitProperty.RequiresPublicConstructors ();
@@ -165,7 +167,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
// Simple getter is not enough - we do detect the field, but we require the field to be compiler generated for this to work
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2077")]
+ [ExpectedWarning ("IL2077", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors))]
// Make sure we don't warn about the field in context of property annotation propagation.
[LogDoesNotContain ("Could not find a unique backing field for property 'System.Type Mono.Linker.Tests.Cases.DataFlow.PropertyDataFlow/TestAutomaticPropagationType::PropertyWithSimpleGetter()'")]
public void TestPropertyWithSimpleGetter ()
@@ -178,13 +180,16 @@ namespace Mono.Linker.Tests.Cases.DataFlow
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
static Type PropertyWithSimpleGetter {
- [UnrecognizedReflectionAccessPattern (typeof (TestAutomaticPropagationType), nameof (PropertyWithSimpleGetter) + ".get", new Type[] { }, returnType: typeof (Type), messageCode: "IL2078")]
+ [ExpectedWarning ("IL2078", nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWithSimpleGetter) + ".get")]
get {
return PropertyWithSimpleGetter_Field;
}
}
- [RecognizedReflectionAccessPattern]
+ // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2077", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors) + "(Type)",
+ nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWhichLooksLikeCompilerGenerated_Field),
+ ProducedBy = ProducedBy.Analyzer)]
public void TestPropertyWhichLooksLikeCompilerGenerated ()
{
// If the property was correctly recognized both the property getter and the backing field should get the annotation.
@@ -197,12 +202,16 @@ namespace Mono.Linker.Tests.Cases.DataFlow
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
static Type PropertyWhichLooksLikeCompilerGenerated {
+ // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2078", nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWhichLooksLikeCompilerGenerated) + ".get",
+ nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWhichLooksLikeCompilerGenerated_Field),
+ ProducedBy = ProducedBy.Analyzer)]
get {
return PropertyWhichLooksLikeCompilerGenerated_Field;
}
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2077")]
+ [ExpectedWarning ("IL2077", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors))]
// Make sure we don't warn about the field in context of property annotation propagation.
[LogDoesNotContain ("Could not find a unique backing field for property 'System.Type Mono.Linker.Tests.Cases.DataFlow.PropertyDataFlow/TestAutomaticPropagationType::InstancePropertyWithStaticField()'")]
public void TestInstancePropertyWithStaticField ()
@@ -218,7 +227,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
Type InstancePropertyWithStaticField {
// Nothing to warn about - the "value" is annotated with PublicConstructors and we're assigning
// it to unannotated field - that's a perfectly valid operation.
- [RecognizedReflectionAccessPattern]
set {
InstancePropertyWithStaticField_Field = value;
}
@@ -235,10 +243,19 @@ namespace Mono.Linker.Tests.Cases.DataFlow
[CompilerGenerated]
private Type PropertyWithDifferentBackingFields_SetterField;
+ // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273
[ExpectedWarning ("IL2042",
- "Mono.Linker.Tests.Cases.DataFlow.PropertyDataFlow.TestAutomaticPropagationType.PropertyWithDifferentBackingFields")]
+ "Mono.Linker.Tests.Cases.DataFlow.PropertyDataFlow.TestAutomaticPropagationType.PropertyWithDifferentBackingFields",
+ ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2078",
+ nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWithDifferentBackingFields) + ".get",
+ "Type",
+ ProducedBy = ProducedBy.Analyzer)]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
Type PropertyWithDifferentBackingFields {
+ [ExpectedWarning ("IL2078",
+ nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWithDifferentBackingFields) + ".get",
+ ProducedBy = ProducedBy.Trimmer)]
get {
return PropertyWithDifferentBackingFields_GetterField;
}
@@ -254,23 +271,95 @@ namespace Mono.Linker.Tests.Cases.DataFlow
PropertyWithExistingAttributes = null;
}
- [ExpectedWarning ("IL2056", "PropertyWithExistingAttributes", "PropertyWithExistingAttributes_Field")]
+ // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2056", "PropertyWithExistingAttributes", "PropertyWithExistingAttributes_Field",
+ ProducedBy = ProducedBy.Trimmer)]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
[CompilerGenerated]
Type PropertyWithExistingAttributes_Field;
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
Type PropertyWithExistingAttributes {
- [ExpectedWarning ("IL2043", "PropertyWithExistingAttributes", "PropertyWithExistingAttributes.get")]
+ // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2043", "PropertyWithExistingAttributes", "PropertyWithExistingAttributes.get",
+ ProducedBy = ProducedBy.Trimmer)]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
get { return PropertyWithExistingAttributes_Field; }
- [ExpectedWarning ("IL2043", "PropertyWithExistingAttributes", "PropertyWithExistingAttributes.set")]
+ // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2043", "PropertyWithExistingAttributes", "PropertyWithExistingAttributes.set",
+ ProducedBy = ProducedBy.Trimmer)]
[param: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
set { PropertyWithExistingAttributes_Field = value; }
}
- [RecognizedReflectionAccessPattern]
+ // When the property annotation conflicts with the getter/setter annotation,
+ // we issue a warning (IL2043 below) but respect the getter/setter annotations.
+ [ExpectedWarning ("IL2072", nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWithConflictingAttributes) + ".get",
+ nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors) + "(Type)")]
+ [ExpectedWarning ("IL2072", nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWithConflictingAttributes) + ".set",
+ nameof (PropertyDataFlow) + "." + nameof (GetTypeWithPublicConstructors) + "()")]
+ public void TestPropertyWithConflictingAttributes ()
+ {
+ PropertyWithConflictingAttributes.RequiresPublicConstructors ();
+ PropertyWithConflictingAttributes.RequiresNonPublicConstructors ();
+ PropertyWithConflictingAttributes = GetTypeWithPublicConstructors ();
+ PropertyWithConflictingAttributes = GetTypeWithNonPublicConstructors ();
+ }
+
+ // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2056", "PropertyWithConflictingAttributes", "PropertyWithConflictingAttributes_Field",
+ ProducedBy = ProducedBy.Trimmer)]
+ [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicConstructors)]
+ [CompilerGenerated]
+ Type PropertyWithConflictingAttributes_Field;
+
+ [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
+ Type PropertyWithConflictingAttributes {
+ // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2043", "PropertyWithConflictingAttributes", "PropertyWithConflictingAttributes.get",
+ ProducedBy = ProducedBy.Trimmer)]
+ [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicConstructors)]
+ get { return PropertyWithConflictingAttributes_Field; }
+
+ // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2043", "PropertyWithConflictingAttributes", "PropertyWithConflictingAttributes.set",
+ ProducedBy = ProducedBy.Trimmer)]
+ [param: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicConstructors)]
+ set { PropertyWithConflictingAttributes_Field = value; }
+ }
+
+ // When the property annotation is DAMT.None and this conflicts with the getter/setter annotations,
+ // we don't produce a warning about the conflict, and just respect the property annotations.
+ [ExpectedWarning ("IL2072", nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWithConflictingNoneAttributes) + ".get",
+ nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors) + "(Type)")]
+ [ExpectedWarning ("IL2072", nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWithConflictingNoneAttributes) + ".set",
+ nameof (PropertyDataFlow) + "." + nameof (GetTypeWithNonPublicConstructors) + "()")]
+ public void TestPropertyWithConflictingNoneAttributes ()
+ {
+ PropertyWithConflictingNoneAttributes.RequiresPublicConstructors ();
+ PropertyWithConflictingNoneAttributes.RequiresNonPublicConstructors ();
+ PropertyWithConflictingNoneAttributes = GetTypeWithPublicConstructors ();
+ PropertyWithConflictingNoneAttributes = GetTypeWithNonPublicConstructors ();
+ }
+
+ [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.None)]
+ [CompilerGenerated]
+ Type PropertyWithConflictingNoneAttributes_Field;
+
+ [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
+ Type PropertyWithConflictingNoneAttributes {
+ // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2078", nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWithConflictingNoneAttributes) + ".get",
+ nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWithConflictingNoneAttributes_Field),
+ ProducedBy = ProducedBy.Analyzer)]
+ [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.None)]
+ get { return PropertyWithConflictingNoneAttributes_Field; }
+
+ [param: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.None)]
+ set { PropertyWithConflictingNoneAttributes_Field = value; }
+ }
+
public void TestPropertyWithIndexerWithMatchingAnnotations ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)] Type myType)
{
var propclass = new PropertyWithIndexer ();
@@ -278,8 +367,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow
propclass[1].RequiresPublicConstructors ();
}
- [UnrecognizedReflectionAccessPattern (typeof (PropertyWithIndexer), "Item.set", new Type[] { typeof (Type) }, messageCode: "IL2067")]
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), "RequiresNonPublicConstructors", new Type[] { typeof (Type) }, messageCode: "IL2072")]
+ // Trimmer and analyzer handle formatting of indexers differently.
+ [ExpectedWarning ("IL2067", nameof (PropertyWithIndexer) + ".Item.set", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2067", nameof (PropertyWithIndexer) + ".this[Int32].set", ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors) + "(Type)")]
[LogDoesNotContain ("'Value passed to parameter 'index' of method 'Mono.Linker.Tests.Cases.DataFlow.PropertyDataFlow.TestAutomaticPropagationType.PropertyWithIndexer.Item.set'")]
public void TestPropertyWithIndexerWithoutMatchingAnnotations (Type myType)
{
@@ -295,7 +386,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
public Type this[int index] {
- [ExpectedWarning ("IL2063", "PropertyWithIndexer.Item.get")]
+ // TODO: warn about unknown types in analyzer: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2063", "PropertyWithIndexer.Item.get",
+ ProducedBy = ProducedBy.Trimmer)]
get => Property_Field[index];
set => Property_Field[index] = value;
}
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/SuppressWarningWithLinkAttributes.cs b/test/Mono.Linker.Tests.Cases/DataFlow/SuppressWarningWithLinkAttributes.cs
index bb890ae64..5210ab617 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/SuppressWarningWithLinkAttributes.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/SuppressWarningWithLinkAttributes.cs
@@ -13,6 +13,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
[SkipKeptItemsValidation]
[SetupLinkAttributesFile ("SuppressWarningWithLinkAttributes.xml")]
[LogDoesNotContain ("Trim analysis warning IL2067: Mono.Linker.Tests.Cases.DataFlow.SuppressWarningWithLinkAttributes::ReadFromInstanceField()")]
+ [ExpectedWarning ("IL2031", "System.DoesNotExistAttribute", FileName = "SuppressWarningWithLinkAttributes.xml")]
+ [ExpectedNoWarnings]
class SuppressWarningWithLinkAttributes
{
public static void Main ()
@@ -26,9 +28,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
Type PropertyWithPublicParameterlessConstructor { get; set; }
- [UnrecognizedReflectionAccessPattern (typeof (SuppressWarningWithLinkAttributes), nameof (RequirePublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2077")]
- [UnrecognizedReflectionAccessPattern (typeof (SuppressWarningWithLinkAttributes), nameof (RequireNonPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2077")]
- [RecognizedReflectionAccessPattern]
+ [ExpectedWarning ("IL2077", nameof (SuppressWarningWithLinkAttributes) + "." + nameof (RequirePublicConstructors))]
+ [ExpectedWarning ("IL2077", nameof (SuppressWarningWithLinkAttributes) + "." + nameof (RequireNonPublicConstructors))]
private void ReadFromInstanceField ()
{
RequirePublicParameterlessConstructor (_typeWithPublicParameterlessConstructor);
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/SuppressWarningWithLinkAttributes.xml b/test/Mono.Linker.Tests.Cases/DataFlow/SuppressWarningWithLinkAttributes.xml
index 699a05d5a..40844528f 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/SuppressWarningWithLinkAttributes.xml
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/SuppressWarningWithLinkAttributes.xml
@@ -7,7 +7,7 @@
</attribute>
<type fullname="Mono.Linker.Tests.Cases.DataFlow.SuppressWarningWithLinkAttributes">
<field name="_typeWithPublicParameterlessConstructor">
- <attribute fullname="System.DoesNotExistattribute" assembly="Mono.Linker.Tests.Cases.Expectations">
+ <attribute fullname="System.DoesNotExistAttribute" assembly="Mono.Linker.Tests.Cases.Expectations">
<argument>0</argument>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute">
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/TypeBaseTypeDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/TypeBaseTypeDataFlow.cs
index 68d232252..0667498f6 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/TypeBaseTypeDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/TypeBaseTypeDataFlow.cs
@@ -13,6 +13,7 @@ using Mono.Linker.Tests.Cases.Expectations.Helpers;
namespace Mono.Linker.Tests.Cases.DataFlow
{
[SkipKeptItemsValidation]
+ [ExpectedNoWarnings]
public class TypeBaseTypeDataFlow
{
public static void Main ()
@@ -47,22 +48,19 @@ namespace Mono.Linker.Tests.Cases.DataFlow
Mixed_Derived.Test (typeof (TestType), 0);
}
- [RecognizedReflectionAccessPattern]
static void TestAllPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] Type derivedType)
{
derivedType.BaseType.RequiresAll ();
}
- [RecognizedReflectionAccessPattern]
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicConstructors), new Type[] { typeof (Type) })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors))]
static void TestPublicConstructorsAreNotPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)] Type derivedType)
{
derivedType.BaseType.RequiresPublicConstructors ();
}
- [RecognizedReflectionAccessPattern]
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) })]
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicEvents), new Type[] { typeof (Type) })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicMethods))]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicEvents))]
static void TestPublicEventsPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicEvents)] Type derivedType)
{
derivedType.BaseType.RequiresPublicEvents ();
@@ -74,9 +72,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
derivedType.BaseType.RequiresNonPublicEvents ();
}
- [RecognizedReflectionAccessPattern]
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) })]
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicFields), new Type[] { typeof (Type) })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicMethods))]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicFields))]
static void TestPublicFieldsPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] Type derivedType)
{
derivedType.BaseType.RequiresPublicFields ();
@@ -88,9 +85,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
derivedType.BaseType.RequiresNonPublicFields ();
}
- [RecognizedReflectionAccessPattern]
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicProperties), new Type[] { typeof (Type) })]
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicMethods), new Type[] { typeof (Type) })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicProperties))]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicMethods))]
static void TestPublicMethodsPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type derivedType)
{
derivedType.BaseType.RequiresPublicMethods ();
@@ -102,23 +98,20 @@ namespace Mono.Linker.Tests.Cases.DataFlow
derivedType.BaseType.RequiresNonPublicMethods ();
}
- [RecognizedReflectionAccessPattern]
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicNestedTypes), new Type[] { typeof (Type) })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicNestedTypes))]
static void TestPublicNestedTypesAreNotPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicNestedTypes)] Type derivedType)
{
derivedType.BaseType.RequiresPublicNestedTypes ();
}
- [RecognizedReflectionAccessPattern]
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicParameterlessConstructor), new Type[] { typeof (Type) })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicParameterlessConstructor))]
static void TestPublicParameterlessConstructorIsNotPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type derivedType)
{
derivedType.BaseType.RequiresPublicParameterlessConstructor ();
}
- [RecognizedReflectionAccessPattern]
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) })]
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicProperties), new Type[] { typeof (Type) })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicMethods))]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicProperties))]
static void TestPublicPropertiesPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicProperties)] Type derivedType)
{
derivedType.BaseType.RequiresPublicProperties ();
@@ -130,49 +123,47 @@ namespace Mono.Linker.Tests.Cases.DataFlow
derivedType.BaseType.RequiresNonPublicProperties ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors), new Type[] { typeof (Type) })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors))]
static void TestNonPublicConstructorsAreNotPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type derivedType)
{
derivedType.BaseType.RequiresNonPublicConstructors ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicEvents), new Type[] { typeof (Type) })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicEvents))]
static void TestNonPublicEventsAreNotPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicEvents)] Type derivedType)
{
derivedType.BaseType.RequiresNonPublicEvents ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicFields), new Type[] { typeof (Type) })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicFields))]
static void TestNonPublicFieldsAreNotPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicFields)] Type derivedType)
{
derivedType.BaseType.RequiresNonPublicFields ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicMethods), new Type[] { typeof (Type) })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicMethods))]
static void TestNonPublicMethodsAreNotPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicMethods)] Type derivedType)
{
derivedType.BaseType.RequiresNonPublicMethods ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicNestedTypes), new Type[] { typeof (Type) })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicNestedTypes))]
static void TestNonPublicNestedTypesAreNotPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicNestedTypes)] Type derivedType)
{
derivedType.BaseType.RequiresNonPublicNestedTypes ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicProperties), new Type[] { typeof (Type) })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicProperties))]
static void TestNonPublicPropertiesAreNotPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicProperties)] Type derivedType)
{
derivedType.BaseType.RequiresNonPublicProperties ();
}
- [RecognizedReflectionAccessPattern]
static void TestInterfacesPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.Interfaces)] Type derivedType)
{
derivedType.BaseType.RequiresInterfaces ();
}
- [RecognizedReflectionAccessPattern]
static void TestCombinationOfPublicsIsPropagated (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicProperties)] Type derivedType)
{
@@ -180,8 +171,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
derivedType.BaseType.RequiresPublicProperties ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicMethods), new Type[] { typeof (Type) })]
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicProperties), new Type[] { typeof (Type) })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicMethods))]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicProperties))]
static void TestCombinationOfNonPublicsIsNotPropagated (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicMethods | DynamicallyAccessedMemberTypes.NonPublicProperties)] Type derivedType)
{
@@ -189,7 +180,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
derivedType.BaseType.RequiresNonPublicProperties ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicMethods), new Type[] { typeof (Type) })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicMethods))]
static void TestCombinationOfPublicAndNonPublicsPropagatesPublicOnly (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicMethods | DynamicallyAccessedMemberTypes.PublicProperties)] Type derivedType)
{
@@ -197,13 +188,13 @@ namespace Mono.Linker.Tests.Cases.DataFlow
derivedType.BaseType.RequiresPublicProperties ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicMethods))]
static void TestNoAnnotation (Type derivedType)
{
derivedType.BaseType.RequiresPublicMethods ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicMethods))]
static void TestAnnotatedAndUnannotated (
Type derivedTypeOne,
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type derivedTypeTwo,
@@ -213,7 +204,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
type.BaseType.RequiresPublicMethods ();
}
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicMethods), new Type[] { typeof (Type) })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicMethods))]
static void TestNull ()
{
Type type = null;
@@ -228,7 +219,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
class Mixed_Derived : Mixed_Base
{
- [RecognizedReflectionAccessPattern]
public static void Test (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type typeWithPublicMethods,
int number)
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/TypeInfoAsTypeDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/TypeInfoAsTypeDataFlow.cs
new file mode 100644
index 000000000..d41bcf284
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/TypeInfoAsTypeDataFlow.cs
@@ -0,0 +1,39 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Diagnostics.CodeAnalysis;
+using System.Reflection;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Helpers;
+
+namespace Mono.Linker.Tests.Cases.DataFlow
+{
+ [SkipKeptItemsValidation]
+ [ExpectedNoWarnings]
+ class TypeInfoAsTypeDataFlow
+ {
+ public static void Main ()
+ {
+ TestNoAnnotations (typeof (TestType).GetTypeInfo ());
+ TestWithAnnotations (typeof (TestType).GetTypeInfo ());
+ }
+
+ [ExpectedWarning ("IL2067", nameof (DataFlowTypeExtensions.RequiresPublicMethods))]
+ static void TestNoAnnotations (TypeInfo t)
+ {
+ t.AsType ().RequiresPublicMethods ();
+ t.AsType ().RequiresNone ();
+ }
+
+ [ExpectedWarning ("IL2067", nameof (DataFlowTypeExtensions.RequiresPublicFields))]
+ static void TestWithAnnotations ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] TypeInfo t)
+ {
+ t.AsType ().RequiresPublicMethods ();
+ t.AsType ().RequiresPublicFields ();
+ t.AsType ().RequiresNone ();
+ }
+
+ class TestType { }
+ }
+}
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/UnresolvedMembers.cs b/test/Mono.Linker.Tests.Cases/DataFlow/UnresolvedMembers.cs
index e65c0e48c..de6707416 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/UnresolvedMembers.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/UnresolvedMembers.cs
@@ -15,6 +15,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
[SkipPeVerify]
[SetupLinkerArgument ("--skip-unresolved", "true")]
[SetupCompileBefore ("UnresolvedLibrary.dll", new[] { "Dependencies/UnresolvedLibrary.cs" }, removeFromLinkerInput: true)]
+ [ExpectedNoWarnings]
class UnresolvedMembers
{
public static void Main ()
@@ -42,7 +43,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{ }
[Kept]
- [ExpectedWarning ("IL2066", "TypeWithUnresolvedGenericArgument")]
+ [ExpectedWarning ("IL2066", "TypeWithUnresolvedGenericArgument")] // Local variable type
+ [ExpectedWarning ("IL2066", "TypeWithUnresolvedGenericArgument")] // Called method declaring type
[ExpectedWarning ("IL2066", nameof (MethodWithUnresolvedGenericArgument))]
static void UnresolvedGenericArgument ()
{
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/VirtualMethodHierarchyDataflowAnnotationValidation.cs b/test/Mono.Linker.Tests.Cases/DataFlow/VirtualMethodHierarchyDataflowAnnotationValidation.cs
index 6d85a8ed4..10b069543 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/VirtualMethodHierarchyDataflowAnnotationValidation.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/VirtualMethodHierarchyDataflowAnnotationValidation.cs
@@ -16,8 +16,12 @@ namespace Mono.Linker.Tests.Cases.DataFlow
// Suppress warnings about accessing methods with annotations via reflection - the test below does that a LOT
// (The test accessed these methods through DynamicallyAccessedMembers annotations which is effectively the same reflection access)
[UnconditionalSuppressMessage ("test", "IL2111")]
+
+ [ExpectedNoWarnings]
class VirtualMethodHierarchyDataflowAnnotationValidation
{
+ // The code below marks methods which have RUC on them, it's not the point of this test to validate these here
+ [UnconditionalSuppressMessage ("test", "IL2026")]
public static void Main ()
{
// The test uses data flow annotation to mark all public methods on the specified types
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/XmlAnnotations.cs b/test/Mono.Linker.Tests.Cases/DataFlow/XmlAnnotations.cs
index ec0c5a0c8..dc3c69ad5 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/XmlAnnotations.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/XmlAnnotations.cs
@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Helpers;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.DataFlow
@@ -14,6 +15,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
[SetupLinkAttributesFile ("XmlAnnotations.xml")]
[ExpectedWarning ("IL2031", "Attribute type 'System.DoesNotExistAttribute' could not be found", FileName = "XmlAnnotations.xml")]
[LogDoesNotContain ("IL2067: Mono.Linker.Tests.Cases.DataFlow.XmlAnnotations.ReadFromInstanceField():*", true)]
+ [ExpectedNoWarnings]
class XmlAnnotations
{
public static void Main ()
@@ -36,77 +38,55 @@ namespace Mono.Linker.Tests.Cases.DataFlow
Type PropertyWithPublicParameterlessConstructor { get; set; }
- [UnrecognizedReflectionAccessPattern (typeof (XmlAnnotations), nameof (RequirePublicConstructors), new Type[] { typeof (Type) })]
- [UnrecognizedReflectionAccessPattern (typeof (XmlAnnotations), nameof (RequireNonPublicConstructors), new Type[] { typeof (Type) })]
- [RecognizedReflectionAccessPattern]
+ [ExpectedWarning ("IL2077", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors))]
+ [ExpectedWarning ("IL2077", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors))]
private void ReadFromInstanceField ()
{
- RequirePublicParameterlessConstructor (_typeWithPublicParameterlessConstructor);
- RequirePublicConstructors (_typeWithPublicParameterlessConstructor);
- RequireNonPublicConstructors (_typeWithPublicParameterlessConstructor);
+ _typeWithPublicParameterlessConstructor.RequiresPublicParameterlessConstructor ();
+ _typeWithPublicParameterlessConstructor.RequiresPublicConstructors ();
+ _typeWithPublicParameterlessConstructor.RequiresNonPublicConstructors ();
}
- [UnrecognizedReflectionAccessPattern (typeof (XmlAnnotations), nameof (RequirePublicConstructors), new Type[] { typeof (Type) })]
- [RecognizedReflectionAccessPattern]
+ [ExpectedWarning ("IL2067", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors))]
private void TwoAnnotatedParameters (
Type type,
Type type2)
{
- RequirePublicParameterlessConstructor (type);
- RequirePublicParameterlessConstructor (type2);
- RequirePublicConstructors (type);
- RequirePublicConstructors (type2);
+ type.RequiresPublicParameterlessConstructor ();
+ type2.RequiresPublicParameterlessConstructor ();
+ type.RequiresPublicConstructors ();
+ type2.RequiresPublicConstructors ();
}
- [UnrecognizedReflectionAccessPattern (typeof (XmlAnnotations), nameof (RequirePublicParameterlessConstructor), new Type[] { typeof (Type) })]
+ [ExpectedWarning ("IL2067", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicParameterlessConstructor))]
private void SpacesBetweenParametersWrongArgument (
Type type,
bool nonused)
{
- RequirePublicParameterlessConstructor (type);
+ type.RequiresPublicParameterlessConstructor ();
}
- [RecognizedReflectionAccessPattern]
private void GenericMethod<T> (
T input,
Type type)
{
- RequirePublicParameterlessConstructor (type);
+ type.RequiresPublicParameterlessConstructor ();
}
- [UnrecognizedReflectionAccessPattern (typeof (XmlAnnotations), nameof (ReturnConstructorsFailure), new Type[] { typeof (Type) },
- returnType: typeof (Type))]
+ [ExpectedWarning ("IL2068", nameof (XmlAnnotations) + "." + nameof (ReturnConstructorsFailure))]
private Type ReturnConstructorsFailure (
Type publicParameterlessConstructorType)
{
return publicParameterlessConstructorType;
}
- [UnrecognizedReflectionAccessPattern (typeof (XmlAnnotations), nameof (RequirePublicConstructors), new Type[] { typeof (Type) })]
- [UnrecognizedReflectionAccessPattern (typeof (XmlAnnotations), nameof (RequireNonPublicConstructors), new Type[] { typeof (Type) })]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors))]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors))]
private void ReadFromInstanceProperty ()
{
- RequirePublicParameterlessConstructor (PropertyWithPublicParameterlessConstructor);
- RequirePublicConstructors (PropertyWithPublicParameterlessConstructor);
- RequireNonPublicConstructors (PropertyWithPublicParameterlessConstructor);
- }
-
- private static void RequirePublicParameterlessConstructor (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
- Type type)
- {
- }
-
- private static void RequirePublicConstructors (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
- Type type)
- {
- }
-
- private static void RequireNonPublicConstructors (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors)]
- Type type)
- {
+ PropertyWithPublicParameterlessConstructor.RequiresPublicParameterlessConstructor ();
+ PropertyWithPublicParameterlessConstructor.RequiresPublicConstructors ();
+ PropertyWithPublicParameterlessConstructor.RequiresNonPublicConstructors ();
}
class TestType { }
@@ -115,32 +95,13 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
Type _typeWithPublicParameterlessConstructor;
- [UnrecognizedReflectionAccessPattern (typeof (NestedType), nameof (RequirePublicConstructors), new Type[] { typeof (Type) })]
- [UnrecognizedReflectionAccessPattern (typeof (NestedType), nameof (RequireConstructors), new Type[] { typeof (Type) })]
- [RecognizedReflectionAccessPattern]
+ [ExpectedWarning ("IL2077", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors))]
+ [ExpectedWarning ("IL2077", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors))]
public void ReadFromInstanceField ()
{
- RequirePublicParameterlessConstructor (_typeWithPublicParameterlessConstructor);
- RequirePublicConstructors (_typeWithPublicParameterlessConstructor);
- RequireConstructors (_typeWithPublicParameterlessConstructor);
- }
-
- private static void RequirePublicParameterlessConstructor (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
- Type type)
- {
- }
-
- private static void RequirePublicConstructors (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
- Type type)
- {
- }
-
- private static void RequireConstructors (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors)]
- Type type)
- {
+ _typeWithPublicParameterlessConstructor.RequiresPublicParameterlessConstructor ();
+ _typeWithPublicParameterlessConstructor.RequiresPublicConstructors ();
+ _typeWithPublicParameterlessConstructor.RequiresNonPublicConstructors ();
}
}
}
diff --git a/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.cs b/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.cs
index 07a2e654a..a798dfa51 100644
--- a/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.cs
+++ b/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.cs
@@ -4,6 +4,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Helpers;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.LinkAttributes
@@ -12,6 +13,7 @@ namespace Mono.Linker.Tests.Cases.LinkAttributes
[SetupCompileResource ("EmbeddedLinkAttributes.xml", "ILLink.LinkAttributes.xml")]
[IgnoreLinkAttributes (false)]
[RemovedResourceInAssembly ("test.exe", "ILLink.LinkAttributes.xml")]
+ [ExpectedNoWarnings]
class EmbeddedLinkAttributes
{
public static void Main ()
@@ -24,47 +26,22 @@ namespace Mono.Linker.Tests.Cases.LinkAttributes
Type _typeWithPublicParameterlessConstructor;
- [UnrecognizedReflectionAccessPattern (typeof (EmbeddedLinkAttributes), nameof (RequirePublicConstructors), new Type[] { typeof (Type) })]
- [UnrecognizedReflectionAccessPattern (typeof (EmbeddedLinkAttributes), nameof (RequireNonPublicConstructors), new Type[] { typeof (Type) })]
- [RecognizedReflectionAccessPattern]
+ [ExpectedWarning ("IL2077", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors))]
+ [ExpectedWarning ("IL2077", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors))]
private void ReadFromInstanceField ()
{
- RequirePublicParameterlessConstructor (_typeWithPublicParameterlessConstructor);
- RequirePublicConstructors (_typeWithPublicParameterlessConstructor);
- RequireNonPublicConstructors (_typeWithPublicParameterlessConstructor);
- }
- private static void RequirePublicParameterlessConstructor (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
- Type type)
- {
- }
-
- private static void RequirePublicConstructors (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
- Type type)
- {
- }
-
- private static void RequireNonPublicConstructors (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors)]
- Type type)
- {
+ _typeWithPublicParameterlessConstructor.RequiresPublicParameterlessConstructor ();
+ _typeWithPublicParameterlessConstructor.RequiresPublicConstructors ();
+ _typeWithPublicParameterlessConstructor.RequiresNonPublicConstructors ();
}
Type _typeWithPublicFields;
- [UnrecognizedReflectionAccessPattern (typeof (EmbeddedLinkAttributes), nameof (RequirePublicConstructors), new Type[] { typeof (Type) })]
- [RecognizedReflectionAccessPattern]
+ [ExpectedWarning ("IL2077", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors))]
private void ReadFromInstanceField2 ()
{
- RequirePublicConstructors (_typeWithPublicFields);
- RequirePublicFields (_typeWithPublicFields);
- }
-
- private static void RequirePublicFields (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)]
- Type type)
- {
+ _typeWithPublicFields.RequiresPublicConstructors ();
+ _typeWithPublicFields.RequiresPublicFields ();
}
}
}
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/ActivatorCreateInstance.cs b/test/Mono.Linker.Tests.Cases/Reflection/ActivatorCreateInstance.cs
index 7eb814fe1..fb8314f9b 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/ActivatorCreateInstance.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/ActivatorCreateInstance.cs
@@ -8,6 +8,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupCSharpCompilerToUse ("csc")]
+ [ExpectedNoWarnings]
[KeptMember (".ctor()")]
public class ActivatorCreateInstance
{
@@ -165,8 +166,8 @@ namespace Mono.Linker.Tests.Cases.Reflection
public FromParameterOnStaticMethodTypeB (int arg) { }
}
- [UnrecognizedReflectionAccessPattern (typeof (Activator), nameof (Activator.CreateInstance), new Type[] { typeof (Type), typeof (object[]) }, messageCode: "IL2067")]
- [UnrecognizedReflectionAccessPattern (typeof (Activator), nameof (Activator.CreateInstance), new Type[] { typeof (Type), typeof (BindingFlags), typeof (Binder), typeof (object[]), typeof (CultureInfo) }, messageCode: "IL2067")]
+ [ExpectedWarning ("IL2067", nameof (Activator) + "." + nameof (Activator.CreateInstance) + "(Type, Object[])")]
+ [ExpectedWarning ("IL2067", nameof (Activator) + "." + nameof (Activator.CreateInstance), nameof (CultureInfo))]
[Kept]
private void FromParameterOnInstanceMethod (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
@@ -188,8 +189,8 @@ namespace Mono.Linker.Tests.Cases.Reflection
public FromParameterOnInstanceMethodType (int arg, int arg2) { }
}
- [UnrecognizedReflectionAccessPattern (typeof (Activator), nameof (Activator.CreateInstance), new Type[] { typeof (Type) }, messageCode: "IL2067")]
- [UnrecognizedReflectionAccessPattern (typeof (Activator), nameof (Activator.CreateInstance), new Type[] { typeof (Type), typeof (object[]) }, messageCode: "IL2067")]
+ [ExpectedWarning ("IL2067", nameof (Activator) + "." + nameof (Activator.CreateInstance) + "(Type)")]
+ [ExpectedWarning ("IL2067", nameof (Activator) + "." + nameof (Activator.CreateInstance) + "(Type, Object[])")]
[Kept]
private static void FromParameterWithNonPublicConstructors (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors)]
@@ -212,7 +213,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
private FromParameterWithNonPublicConstructorsType (int arg, int arg2) { }
}
- [UnrecognizedReflectionAccessPattern (typeof (Activator), nameof (Activator.CreateInstance), new Type[] { typeof (Type), typeof (BindingFlags), typeof (Binder), typeof (object[]), typeof (CultureInfo) }, messageCode: "IL2067")]
+ [ExpectedWarning ("IL2067", nameof (Activator) + "." + nameof (Activator.CreateInstance))]
[Kept]
private static void FromParameterWithPublicConstructors (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
@@ -319,16 +320,14 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Activator), nameof (Activator.CreateInstance), new Type[] { typeof (string), typeof (string) },
- messageCode: "IL2032", message: new string[] { "assemblyName" })]
+ [ExpectedWarning ("IL2032", nameof (Activator) + "." + nameof (Activator.CreateInstance), "assemblyName")]
private static void WithNullAssemblyName ()
{
Activator.CreateInstance (null, "Mono.Linker.Tests.Cases.Reflection.ActivatorCreateInstance+WithAssemblyNameParameterless1");
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Activator), nameof (Activator.CreateInstance), new Type[] { typeof (string), typeof (string) },
- messageCode: "IL2061", message: new string[] { "NonExistingAssembly" })]
+ [ExpectedWarning ("IL2061", nameof (Activator) + "." + nameof (Activator.CreateInstance), "NonExistingAssembly")]
private static void WithNonExistingAssemblyName ()
{
Activator.CreateInstance ("NonExistingAssembly", "Mono.Linker.Tests.Cases.Reflection.ActivatorCreateInstance+WithAssemblyNameParameterless1");
@@ -338,15 +337,13 @@ namespace Mono.Linker.Tests.Cases.Reflection
private static string _typeNameField;
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Activator), nameof (Activator.CreateInstance), new Type[] { typeof (string), typeof (string), typeof (object[]) },
- messageCode: "IL2032", message: new string[] { "typeName" })]
+ [ExpectedWarning ("IL2032", nameof (Activator) + "." + nameof (Activator.CreateInstance), "typeName")]
private static void WithAssemblyAndUnknownTypeName ()
{
Activator.CreateInstance ("test", _typeNameField, new object[] { });
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void WithAssemblyAndNonExistingTypeName ()
{
Activator.CreateInstance ("test", "NonExistingType", new object[] { });
@@ -381,7 +378,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void AppDomainCreateInstance ()
{
// Just a basic test that these are all recognized, we're not testing that it marks correctly as it has the exact same implementation
@@ -404,9 +400,9 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Assembly), nameof (Assembly.CreateInstance), new Type[] { typeof (string) }, messageCode: "IL2058")]
- [UnrecognizedReflectionAccessPattern (typeof (Assembly), nameof (Assembly.CreateInstance), new Type[] { typeof (string), typeof (bool) }, messageCode: "IL2058")]
- [UnrecognizedReflectionAccessPattern (typeof (Assembly), nameof (Assembly.CreateInstance), new Type[] { typeof (string), typeof (bool), typeof (BindingFlags), typeof (Binder), typeof (object[]), typeof (CultureInfo), typeof (object[]) }, messageCode: "IL2058")]
+ [ExpectedWarning ("IL2058", nameof (Assembly) + "." + nameof (Assembly.CreateInstance) + "(String)")]
+ [ExpectedWarning ("IL2058", nameof (Assembly) + "." + nameof (Assembly.CreateInstance) + "(String, Boolean)")]
+ [ExpectedWarning ("IL2058", nameof (Assembly) + "." + nameof (Assembly.CreateInstance), nameof (BindingFlags))]
private static void UnsupportedCreateInstance ()
{
typeof (ActivatorCreateInstance).Assembly.CreateInstance ("NonExistent");
@@ -428,7 +424,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestCreateInstanceOfTWithConcreteType ()
{
Activator.CreateInstance<TestCreateInstanceOfTWithConcreteTypeType> ();
@@ -448,7 +443,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestCreateInstanceOfTWithNewConstraint<T> () where T : new()
{
Activator.CreateInstance<T> ();
@@ -468,6 +462,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
[Kept]
[ExpectedWarning ("IL2091", nameof (Activator), nameof (Activator.CreateInstance) + "<T>")]
+ [ExpectedWarning ("IL2091", nameof (Activator), nameof (Activator.CreateInstance) + "<T>")]
// Warnings are currently duplicated in NETCORE (annotation and intrinsics) - but they're not identical in this case.
// See https://github.com/dotnet/linker/issues/1483
private static void TestCreateInstanceOfTWithNoConstraint<T> ()
@@ -489,7 +484,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestCreateInstanceOfTWithDataflow<
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor),
KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] T> ()
@@ -507,14 +501,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestNullArgsOnKnownType ()
{
Activator.CreateInstance (typeof (TestNullArgsType), null);
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestNullArgsOnAnnotatedType (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor),
KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] Type type)
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithSweptReferences.cs b/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithSweptReferences.cs
index 5cecf5e5d..526376526 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithSweptReferences.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithSweptReferences.cs
@@ -5,6 +5,7 @@ using Mono.Linker.Tests.Cases.Reflection.Dependencies;
namespace Mono.Linker.Tests.Cases.Reflection
{
+ [ExpectedNoWarnings]
[SetupCSharpCompilerToUse ("csc")]
[SetupCompileBefore ("unusedreference.dll", new[] { "Dependencies/UnusedAssemblyDependency.cs" })]
[SetupCompileBefore ("reference.dll", new[] { "Dependencies/AssemblyDependency.cs" }, addAsReference: false)]
@@ -19,7 +20,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void AccessNonExistingTypeInAssembly ()
{
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/ConstructorUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/ConstructorUsedViaReflection.cs
index dde8f46f9..5c28deafe 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/ConstructorUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/ConstructorUsedViaReflection.cs
@@ -7,6 +7,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupCSharpCompilerToUse ("csc")]
+ [ExpectedNoWarnings]
public class ConstructorUsedViaReflection
{
public static void Main ()
@@ -58,9 +59,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (Type[]) },
- typeof (EmptyTypes), nameof (EmptyTypes), new Type[0])]
static void TestConstructorWithTypes_EmptyTypes ()
{
var constructor = typeof (EmptyTypes).GetConstructor (new Type[] { });
@@ -68,7 +66,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestConstructorWithTypes_NonEmptyTypes ()
{
var constructor = typeof (GetConstructor_Types).GetConstructor (new Type[] { typeof (int) });
@@ -76,7 +73,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestConstructorWithTypes_EmptyTypes_DataFlow (
[KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
@@ -87,8 +83,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (Type[]) }, messageCode: "IL2070")]
+ [ExpectedWarning ("IL2070", nameof (Type.GetConstructor))]
static void TestConstructorWithTypes_NonEmptyTypes_DataFlow (
[KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
@@ -123,9 +118,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (BindingFlags), typeof (Binder), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (KnownBindingFlags), nameof (KnownBindingFlags), new Type[0])]
public static void TestWithBindingFlags ()
{
var constructor = typeof (KnownBindingFlags).GetConstructor (BindingFlags.Public, GetNullValue ("some argument", 2, 3), new Type[] { }, new ParameterModifier[] { });
@@ -157,8 +149,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (BindingFlags), typeof (Binder), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (UnknownBindingFlags), nameof (UnknownBindingFlags), new Type[0])]
public static void TestWithUnknownBindingFlags (BindingFlags bindingFlags)
{
// Since the binding flags are not known linker should mark all constructors on the type
@@ -187,9 +177,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
{ }
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (BindingFlags), typeof (Binder), typeof (CallingConventions), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (GetConstructor_BindingAttr_Binder_CallConvention_Types_Modifiers), nameof (GetConstructor_BindingAttr_Binder_CallConvention_Types_Modifiers), new Type[0])]
public static void TestWithCallingConvention ()
{
var constructor = typeof (GetConstructor_BindingAttr_Binder_CallConvention_Types_Modifiers).GetConstructor (BindingFlags.Public, GetNullValue ("some argument", 2, 3), CallingConventions.HasThis, new Type[] { }, new ParameterModifier[] { });
@@ -236,9 +223,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (BindingFlags), typeof (Type[]) },
- typeof (GetConstructor_BindingAttr_Types), nameof (GetConstructor_BindingAttr_Types), new Type[0])]
static void TestWithBindingFlagsAndTypes_EmptyTypes ()
{
var constructor = typeof (GetConstructor_BindingAttr_Types).GetConstructor (BindingFlags.Public, new Type[] { });
@@ -246,7 +230,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestWithBindingFlagsAndTypes_NonEmptyTypes ()
{
var constructor = typeof (NonEmptyTypes).GetConstructor (BindingFlags.Public, new Type[] { typeof (TestType) });
@@ -254,7 +237,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestWithBindingFlagsAndTypes_EmptyTypes_DataFlow (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
[KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))]
@@ -264,8 +246,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (BindingFlags), typeof (Type[]) }, messageCode: "IL2070")]
+ [ExpectedWarning ("IL2070", nameof (Type.GetConstructor))]
static void TestWithBindingFlagsAndTypes_NonEmptyTypes_DataFlow (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
[KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))]
@@ -289,8 +270,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
return null;
}
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (Type[]) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetConstructor" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetConstructor")]
[Kept]
static void TestDataFlowType ()
{
@@ -342,12 +322,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (BindingFlags), typeof (Binder), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (IfConstructor), nameof (IfConstructor), new Type[0])]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (BindingFlags), typeof (Binder), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (ElseConstructor), nameof (ElseConstructor), new Type[0])]
public static void TestIfElse (bool decision)
{
Type myType;
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/ConstructorsUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/ConstructorsUsedViaReflection.cs
index be6d2408b..78ed3dad1 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/ConstructorsUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/ConstructorsUsedViaReflection.cs
@@ -21,21 +21,18 @@ namespace Mono.Linker.Tests.Cases.Reflection
TestIfElse (true);
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestGetConstructors ()
{
var constructors = typeof (SimpleGetConstructors).GetConstructors ();
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestWithBindingFlags ()
{
var constructors = typeof (ConstructorsBindingFlags).GetConstructors (BindingFlags.Public | BindingFlags.Static);
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestWithUnknownBindingFlags (BindingFlags bindingFlags)
{
@@ -44,7 +41,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNullType ()
{
Type type = null;
@@ -57,8 +53,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
return null;
}
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetConstructors), new Type[] { typeof (BindingFlags) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetConstructors" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetConstructors")]
[Kept]
static void TestDataFlowType ()
{
@@ -67,14 +62,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestDataFlowWithAnnotation ([KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))][DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)] Type type)
{
var constructors = type.GetConstructors (BindingFlags.Public | BindingFlags.Static);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIfElse (bool decision)
{
Type myType;
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs
index 5f93cf879..5dbad0c58 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs
@@ -6,6 +6,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupCSharpCompilerToUse ("csc")]
+ [ExpectedNoWarnings]
public class EventUsedViaReflection
{
public static void Main ()
@@ -31,9 +32,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetEvent), new Type[] { typeof (string) },
- typeof (Foo), nameof (Foo.Event), (Type[]) null)]
static void TestByName ()
{
var eventInfo = typeof (Foo).GetEvent ("Event");
@@ -111,8 +109,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetEvent), new Type[] { typeof (string) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetEvent" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetEvent")]
static void TestDataFlowType ()
{
Type type = FindType ();
@@ -120,15 +117,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetEvent), new Type[] { typeof (string) },
- typeof (IfClass), nameof (IfClass.IfEvent), (Type[]) null)]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetEvent), new Type[] { typeof (string) },
- typeof (IfClass), nameof (IfClass.ElseEvent), (Type[]) null)]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetEvent), new Type[] { typeof (string) },
- typeof (ElseClass), nameof (ElseClass.IfEvent), (Type[]) null)]
static void TestIfElse (int i)
{
Type myType;
@@ -147,9 +135,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetEvent), new Type[] { typeof (string) },
- typeof (BaseClass), nameof (BaseClass.PublicEventOnBase), (Type[]) null)]
static void TestEventInBaseType ()
{
typeof (DerivedClass).GetEvent ("ProtectedEventOnBase"); // Will not mark anything as it only works on public events
@@ -157,9 +142,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetEvent), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (IgnoreCaseBindingFlagsClass), nameof (IgnoreCaseBindingFlagsClass.PublicEvent), (Type[]) null)]
static void TestIgnoreCaseBindingFlags ()
{
typeof (IgnoreCaseBindingFlagsClass).GetEvent ("publicevent", BindingFlags.IgnoreCase | BindingFlags.Public);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/EventsUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/EventsUsedViaReflection.cs
index 0c2d15582..53a7494f6 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/EventsUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/EventsUsedViaReflection.cs
@@ -28,14 +28,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestGetEvents ()
{
var events = typeof (Foo).GetEvents ();
}
[Kept]
- [RecognizedReflectionAccessPattern]
// The event will not be kept as it's internal and the behavior of Type.GetEvents() is to only return public events
// But we don't mark it as unrecognized access pattern - we did recognize it fully, just didn't find the event being asked for
// The behavior of the code will not change by linking it:
@@ -47,14 +45,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestBindingFlags ()
{
var events = typeof (Bar).GetEvents (BindingFlags.NonPublic);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestUnknownBindingFlags (BindingFlags bindingFlags)
{
// Since the binding flags are not known linker should mark all events on the type
@@ -62,7 +58,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNullType ()
{
Type type = null;
@@ -76,8 +71,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetEvents), new Type[] { typeof (BindingFlags) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetEvents" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetEvents")]
static void TestDataFlowType ()
{
Type type = FindType ();
@@ -85,14 +79,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestDataFlowWithAnnotation ([KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))][DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicEvents)] Type type)
{
var events = type.GetEvents (BindingFlags.Public | BindingFlags.Static);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIfElse (int i)
{
Type myType;
@@ -105,14 +97,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIgnoreCaseBindingFlags ()
{
var events = typeof (IgnoreCaseBindingFlagsClass).GetEvents (BindingFlags.IgnoreCase | BindingFlags.Public);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestUnsupportedBindingFlags ()
{
var events = typeof (PutRefDispPropertyBindingFlagsClass).GetEvents (BindingFlags.PutRefDispProperty);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/ExpressionCallString.cs b/test/Mono.Linker.Tests.Cases/Reflection/ExpressionCallString.cs
index 699bb9d9d..bb89b436d 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/ExpressionCallString.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/ExpressionCallString.cs
@@ -118,13 +118,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
class TestUnknownType
{
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Expression), nameof (Expression.Call),
- new Type[] { typeof (Type), typeof (string), typeof (Type[]), typeof (Expression[]) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (Expression) + "." + nameof (Expression.Call))]
public static void Test ()
{
// Keep all methods of the type that made the call
Expression.Call (GetUnknownType (), "This string will not be reached", Type.EmptyTypes);
- // UnrecognizedReflectionAccessPattern
+ // IL2072
Expression.Call (TriggerUnrecognizedPattern (), "This string will not be reached", Type.EmptyTypes);
}
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/ExpressionFieldString.cs b/test/Mono.Linker.Tests.Cases/Reflection/ExpressionFieldString.cs
index 0a6959ce8..c2399e92c 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/ExpressionFieldString.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/ExpressionFieldString.cs
@@ -7,10 +7,10 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
[Reference ("System.Core.dll")]
+ [ExpectedNoWarnings]
public class ExpressionFieldString
{
- [UnrecognizedReflectionAccessPattern (typeof (Expression), nameof (Expression.Field),
- new Type[] { typeof (Expression), typeof (Type), typeof (string) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (Expression) + "." + nameof (Expression.Field))]
public static void Main ()
{
Expression.Field (Expression.Parameter (typeof (int), ""), typeof (ExpressionFieldString), "Field");
@@ -18,8 +18,9 @@ namespace Mono.Linker.Tests.Cases.Reflection
Expression.Field (null, typeof (Derived), "_protectedFieldOnBase");
Expression.Field (null, typeof (Derived), "_publicFieldOnBase");
UnknownType.Test ();
+ UnknownTypeNoAnnotation.Test ();
UnknownString.Test ();
- Expression.Field (null, GetType (), "This string will not be reached"); // UnrecognizedReflectionAccessPattern
+ Expression.Field (null, GetType (), "This string will not be reached"); // IL2072
}
[Kept]
@@ -61,6 +62,26 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
+ class UnknownTypeNoAnnotation
+ {
+ public static int Field1;
+ private int Field2;
+
+ [ExpectedWarning ("IL2072", "'type'")]
+ [Kept]
+ public static void Test ()
+ {
+ Expression.Field (null, GetType (), "This string will not be reached");
+ }
+
+ [Kept]
+ static Type GetType ()
+ {
+ return typeof (UnknownType);
+ }
+ }
+
+ [Kept]
class UnknownString
{
[Kept]
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/ExpressionNewType.cs b/test/Mono.Linker.Tests.Cases/Reflection/ExpressionNewType.cs
index a137d122c..9e06ccb43 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/ExpressionNewType.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/ExpressionNewType.cs
@@ -8,6 +8,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
[Reference ("System.Core.dll")]
+ [ExpectedNoWarnings]
public class ExpressionNewType
{
public static void Main ()
@@ -25,11 +26,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
Expression.New (5 + 7 == 12 ? null : typeof (RemovedType));
}
- #region RecognizedReflectionAccessPatterns
- [RecognizedReflectionAccessPattern (
- typeof (Expression), nameof (Expression.New), new Type[] { typeof (Type) }, typeof (A), "A", new Type[0])]
- [RecognizedReflectionAccessPattern (
- typeof (Expression), nameof (Expression.New), new Type[] { typeof (Type) }, typeof (B), "B", new Type[0])]
[Kept]
static void Branch_SystemTypeValueNode (int i)
{
@@ -47,25 +43,22 @@ namespace Mono.Linker.Tests.Cases.Reflection
Expression.New (T);
}
- #endregion
- #region UnrecognizedReflectionAccessPatterns
- [UnrecognizedReflectionAccessPattern (typeof (Expression), nameof (Expression.New), new Type[] { typeof (Type) }, messageCode: "IL2067")]
+ [ExpectedWarning ("IL2067", nameof (Expression) + "." + nameof (Expression.New))]
[Kept]
static void Branch_MethodParameterValueNode (Type T)
{
Expression.New (T);
}
- [UnrecognizedReflectionAccessPattern (typeof (Expression), nameof (Expression.New), new Type[] { typeof (Type) }, messageCode: "IL2072")]
- [UnrecognizedReflectionAccessPattern (typeof (Expression), nameof (Expression.New), new Type[] { typeof (Type) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (Expression) + "." + nameof (Expression.New), "'System." + nameof (Type) + "." + nameof (Type.GetType))]
+ [ExpectedWarning ("IL2072", nameof (Expression) + "." + nameof (Expression.New), nameof (ExpressionNewType) + "." + nameof (ExpressionNewType.GetType))]
[Kept]
static void Branch_UnrecognizedPatterns ()
{
Expression.New (Type.GetType ("RemovedType"));
Expression.New (GetType ());
}
- #endregion
#region Helpers
[Kept]
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/ExpressionPropertyMethodInfo.cs b/test/Mono.Linker.Tests.Cases/Reflection/ExpressionPropertyMethodInfo.cs
index 8a0b2b3b0..b4d9613ae 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/ExpressionPropertyMethodInfo.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/ExpressionPropertyMethodInfo.cs
@@ -76,7 +76,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void Test ()
{
Expression<Func<int>> staticGetter = () => StaticProperty;
@@ -124,7 +123,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void Test ()
{
Expression.Property (null, typeof (PropertySetter).GetMethod ("set_StaticProperty"));
@@ -136,7 +134,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNull ()
{
MethodInfo mi = null;
@@ -144,16 +141,13 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (
- typeof (Expression), nameof (Expression.Property), new Type[] { typeof (Expression), typeof (MethodInfo) },
- messageCode: "IL2103")]
+ [ExpectedWarning ("IL2103", nameof (Expression) + "." + nameof (Expression.Property))]
static void TestNonPropertyMethod ()
{
Expression.Property (null, typeof (ExpressionPropertyMethodInfo).GetMethod (nameof (TestNonPropertyMethod), BindingFlags.NonPublic | BindingFlags.Static));
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNonExistentMethod ()
{
Expression.Property (null, typeof (ExpressionPropertyMethodInfo).GetMethod ("NonExistent"));
@@ -181,7 +175,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void Test (int p)
{
MethodInfo mi;
@@ -202,9 +195,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (
- typeof (Expression), nameof (Expression.Property), new Type[] { typeof (Expression), typeof (MethodInfo) },
- messageCode: "IL2103")]
+ [ExpectedWarning ("IL2103", nameof (Expression) + "." + nameof (Expression.Property))]
static void TestUnknownMethod (MethodInfo mi)
{
Expression.Property (null, mi);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/ExpressionPropertyString.cs b/test/Mono.Linker.Tests.Cases/Reflection/ExpressionPropertyString.cs
index 7379710bd..13de4491d 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/ExpressionPropertyString.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/ExpressionPropertyString.cs
@@ -9,10 +9,10 @@ namespace Mono.Linker.Tests.Cases.Reflection
// Explicitly use roslyn to try and get a compiler that supports defining a static property without a setter
[SetupCSharpCompilerToUse ("csc")]
[Reference ("System.Core.dll")]
+ [ExpectedNoWarnings]
public class ExpressionPropertyString
{
- [UnrecognizedReflectionAccessPattern (typeof (Expression), nameof (Expression.Property),
- new Type[] { typeof (Expression), typeof (Type), typeof (string) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (Expression) + "." + nameof (Expression.Property))]
public static void Main ()
{
Expression.Property (Expression.Parameter (typeof (int), ""), typeof (ExpressionPropertyString), "Property");
@@ -21,7 +21,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
Expression.Property (null, typeof (Derived), "PublicPropertyOnBase");
UnknownType.Test ();
UnknownString.Test ();
- Expression.Property (null, GetType (), "This string will not be reached"); // UnrecognizedReflectionAccessPattern
+ Expression.Property (null, GetType (), "This string will not be reached"); // IL2072
}
[Kept]
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs
index 94535adb1..c0fad7206 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs
@@ -6,6 +6,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupCSharpCompilerToUse ("csc")]
+ [ExpectedNoWarnings]
public class FieldUsedViaReflection
{
public static void Main ()
@@ -29,9 +30,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetField), new Type[] { typeof (string) },
- typeof (FieldUsedViaReflection), nameof (FieldUsedViaReflection.publicField), (Type[]) null)]
static void TestByName ()
{
var field = typeof (FieldUsedViaReflection).GetField ("publicField");
@@ -46,9 +44,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetField), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (Foo), nameof (Foo.field), (Type[]) null)]
static void TestNameBindingFlags ()
{
var field = typeof (Foo).GetField ("field", BindingFlags.Static);
@@ -106,8 +101,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetField), new Type[] { typeof (string) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetField" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetField")]
static void TestDataFlowType ()
{
Type type = FindType ();
@@ -115,12 +109,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetField), new Type[] { typeof (string) },
- typeof (IfClass), nameof (IfClass.ifField), (Type[]) null)]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetField), new Type[] { typeof (string) },
- typeof (ElseClass), nameof (ElseClass.elseField), (Type[]) null)]
static void TestIfElse (int i)
{
Type myType;
@@ -139,9 +127,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetField), new Type[] { typeof (string) },
- typeof (BaseClass), nameof (BaseClass.publicFieldOnBase), (Type[]) null)]
static void TestFieldInBaseType ()
{
var protectedField = typeof (DerivedClass).GetField ("protectedFieldOnBase"); // Will not be marked - only public fields work this way
@@ -149,9 +134,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetField), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (IgnoreCaseBindingFlagsClass), nameof (IgnoreCaseBindingFlagsClass.publicField), (Type[]) null)]
static void TestIgnoreCaseBindingFlags ()
{
var field = typeof (IgnoreCaseBindingFlagsClass).GetField ("publicfield", BindingFlags.IgnoreCase | BindingFlags.Public);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/FieldsUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/FieldsUsedViaReflection.cs
index 7f805345e..ab50a5dac 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/FieldsUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/FieldsUsedViaReflection.cs
@@ -24,21 +24,18 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestGetFields ()
{
var fields = typeof (FieldsUsedViaReflection).GetFields ();
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestBindingFlags ()
{
var fields = typeof (Foo).GetFields (BindingFlags.Public);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestUnknownBindingFlags (BindingFlags bindingFlags)
{
// Since the binding flags are not known linker should mark all fields on the type
@@ -46,7 +43,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNullType ()
{
Type type = null;
@@ -60,8 +56,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetFields), new Type[] { typeof (BindingFlags) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetFields" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetFields")]
static void TestDataFlowType ()
{
Type type = FindType ();
@@ -69,14 +64,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestDataFlowWithAnnotation ([KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))][DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] Type type)
{
var fields = type.GetFields (BindingFlags.Public | BindingFlags.Static);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIfElse (int i)
{
Type myType;
@@ -89,14 +82,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIgnoreCaseBindingFlags ()
{
var fields = typeof (IgnoreCaseBindingFlagsClass).GetFields (BindingFlags.IgnoreCase | BindingFlags.Public);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestUnsupportedBindingFlags ()
{
var fields = typeof (PutDispPropertyBindingFlagsClass).GetFields (BindingFlags.PutDispProperty);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/MemberUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/MemberUsedViaReflection.cs
index a73ed2d7a..828ce4d77 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/MemberUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/MemberUsedViaReflection.cs
@@ -7,6 +7,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupCSharpCompilerToUse ("csc")]
+ [ExpectedNoWarnings]
public class MemberUsedViaReflection
{
public static void Main ()
@@ -24,7 +25,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
TestIfElse (true);
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestWithName ()
{
@@ -32,21 +32,18 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestWithPrefixLookup ()
{
var members = typeof (PrefixLookupType).GetMember ("PrefixLookup*");
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestWithBindingFlags ()
{
var members = typeof (BindingFlagsType).GetMember ("PrefixLookup*", BindingFlags.Public | BindingFlags.NonPublic);
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestWithUnknownBindingFlags (BindingFlags bindingFlags)
{
@@ -54,7 +51,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
var members = typeof (UnknownBindingFlags).GetMember ("PrefixLookup*", bindingFlags);
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestWithMemberTypes ()
{
@@ -63,7 +59,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
var members = typeof (TestMemberTypes).GetMember ("PrefixLookup*", MemberTypes.Method, BindingFlags.Public);
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestNullType ()
{
@@ -77,8 +72,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
return null;
}
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetMember), new Type[] { typeof (string) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetMember" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetMember")]
[Kept]
static void TestDataFlowType ()
{
@@ -87,7 +81,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestDataFlowWithAnnotation ([KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors |
DynamicallyAccessedMemberTypes.PublicEvents |
@@ -100,7 +93,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIfElse (bool decision)
{
Type myType;
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/MembersUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/MembersUsedViaReflection.cs
index 5a7fe375e..8a20f7733 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/MembersUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/MembersUsedViaReflection.cs
@@ -21,21 +21,18 @@ namespace Mono.Linker.Tests.Cases.Reflection
TestIfElse (true);
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestGetMembers ()
{
var members = typeof (SimpleGetMembers).GetMembers ();
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestWithBindingFlags ()
{
var members = typeof (MembersBindingFlags).GetMembers (BindingFlags.Public);
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestWithUnknownBindingFlags (BindingFlags bindingFlags)
{
@@ -44,7 +41,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNullType ()
{
Type type = null;
@@ -57,8 +53,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
return null;
}
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetMembers), new Type[] { typeof (BindingFlags) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetMembers" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetMembers")]
[Kept]
static void TestDataFlowType ()
{
@@ -67,7 +62,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestDataFlowWithAnnotation ([KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors |
DynamicallyAccessedMemberTypes.PublicEvents |
@@ -80,7 +74,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIfElse (bool decision)
{
Type myType;
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs
index 7a9475542..116cabad0 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs
@@ -7,6 +7,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupCSharpCompilerToUse ("csc")]
+ [ExpectedNoWarnings]
[SetupLinkerArgument ("--disable-opt", "unreachablebodies")]
public class MethodUsedViaReflection
{
@@ -73,9 +74,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string) },
- typeof (GetMethod_Name), nameof (GetMethod_Name.OnlyCalledViaReflection), new Type[0])]
public static void TestName ()
{
var method = typeof (GetMethod_Name).GetMethod ("OnlyCalledViaReflection");
@@ -83,7 +81,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void TestNamePrivate ()
{
// This should fail at runtime, since GetMethod(name) only works on public methods
@@ -121,9 +118,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (Type[]) },
- typeof (GetMethod_Name_Types), nameof (GetMethod_Name_Types.OnlyCalledViaReflection), new Type[0])]
public static void TestNameAndType ()
{
// Currently linker doesn't analyze the Type[] parameter and thus it marks all methods with the name and matching binding flags (public in this case)
@@ -159,9 +153,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (GetMethod_Name_BindingAttr), nameof (GetMethod_Name_BindingAttr.OnlyCalledViaReflection), new Type[0])]
public static void TestExplicitBindingFlags ()
{
var method = typeof (GetMethod_Name_BindingAttr).GetMethod ("OnlyCalledViaReflection", BindingFlags.Static | BindingFlags.Public);
@@ -197,7 +188,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void TestUnknownBindingFlags (BindingFlags bindingFlags)
{
// Since the binding flags are not known linker should mark all methods on the type
@@ -216,7 +206,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void TestUnknownBindingFlagsAndName (BindingFlags bindingFlags, string name)
{
// Since the binding flags and name are not known linker should mark all methods on the type
@@ -253,7 +242,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void TestUnknownNullBindingFlags (BindingFlags bindingFlags)
{
// The case here is a pattern which linker doesn't recognize (unlike the test case above, which passes a recognized
@@ -364,7 +352,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void TestNameBindingFlagsAndParameterModifier ()
{
var method = typeof (GetMethod_Name_BindingAttr_Binder_Types_Modifiers).GetMethod ("OnlyCalledViaReflection", BindingFlags.Public, null, new Type[] { }, null);
@@ -396,9 +383,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (BindingFlags), typeof (Binder), typeof (CallingConventions), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (GetMethod_Name_BindingAttr_Binder_CallConvention_Types_Modifiers), nameof (GetMethod_Name_BindingAttr_Binder_CallConvention_Types_Modifiers.OnlyCalledViaReflection), new Type[0])]
public static void TestNameBindingFlagsCallingConventionParameterModifier ()
{
var method = typeof (GetMethod_Name_BindingAttr_Binder_CallConvention_Types_Modifiers).GetMethod ("OnlyCalledViaReflection", BindingFlags.NonPublic, null, CallingConventions.Standard, new Type[] { }, null);
@@ -432,7 +416,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void TestNameBindingFlagsAndTypes ()
{
var method = typeof (GetMethod_Name_BindingAttr_Types).GetMethod ("OnlyCalledViaReflection", BindingFlags.Public, new Type[] { });
@@ -464,9 +447,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (int), typeof (Type[]) },
- typeof (GetMethod_Name_GenericParameterCount_Types), nameof (GetMethod_Name_GenericParameterCount_Types.OnlyCalledViaReflection), new Type[] { typeof (int), typeof (int) })]
public static void TestNameWithIntAndType ()
{
var method = typeof (GetMethod_Name_GenericParameterCount_Types).GetMethod ("OnlyCalledViaReflection", 1, new Type[] { typeof (int) });
@@ -498,9 +478,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (int), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (GetMethod_Name_GenericParameterCount_Types_Modifiers), nameof (GetMethod_Name_GenericParameterCount_Types_Modifiers.OnlyCalledViaReflection), new Type[] { typeof (int), typeof (int) })]
public static void TestNameWithIntAndTypeAndModifiers ()
{
var method = typeof (GetMethod_Name_GenericParameterCount_Types_Modifiers).GetMethod ("OnlyCalledViaReflection", 1, new Type[] { typeof (int) }, null);
@@ -532,7 +509,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void TestNameWithIntAndBindingFlags ()
{
var method = typeof (GetMethod_Name_GenericParameterCount_BindingAttr_Binder_Types_Modifiers)
@@ -566,7 +542,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void TestNameWithIntAndPrivateBindingFlags ()
{
var method = typeof (GetMethod_Name_GenericParameterCount_BindingAttr_Binder_Types_Modifiers_PrivateBinding)
@@ -598,9 +573,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (int), typeof (BindingFlags), typeof (Binder), typeof (CallingConventions), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (GetMethod_Name_GenericParameterCount_BindingAttr_Binder_CallConvention_Types_Modifiers), nameof (GetMethod_Name_GenericParameterCount_BindingAttr_Binder_CallConvention_Types_Modifiers.OnlyCalledViaReflection), new Type[0])]
public static void TestNameWithIntBindingFlagsCallingConventionParameter ()
{
var method = typeof (GetMethod_Name_GenericParameterCount_BindingAttr_Binder_CallConvention_Types_Modifiers).GetMethod ("OnlyCalledViaReflection", 1, BindingFlags.Static | BindingFlags.NonPublic, null, CallingConventions.Any, new Type[] { }, null);
@@ -610,28 +582,24 @@ namespace Mono.Linker.Tests.Cases.Reflection
#endif
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNullName ()
{
var method = typeof (MethodUsedViaReflection).GetMethod (null);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestEmptyName ()
{
var method = typeof (MethodUsedViaReflection).GetMethod (string.Empty);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNonExistingName ()
{
var method = typeof (MethodUsedViaReflection).GetMethod ("NonExisting");
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNullType ()
{
Type type = null;
@@ -645,8 +613,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (BindingFlags) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetMethod" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetMethod")]
static void TestDataFlowType ()
{
Type type = FindType ();
@@ -716,21 +683,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (BindingFlags), typeof (Binder), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (IfClass), nameof (IfClass.OnlyCalledViaReflection), new Type[0])]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (BindingFlags), typeof (Binder), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (IfClass), nameof (IfClass.ElseIfCall), new Type[0])]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (BindingFlags), typeof (Binder), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (ElseIfClass), nameof (ElseIfClass.OnlyCalledViaReflection), new Type[0])]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (BindingFlags), typeof (Binder), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (ElseIfClass), nameof (ElseIfClass.ElseIfCall), new Type[0])]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (BindingFlags), typeof (Binder), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (ElseClass), nameof (ElseClass.OnlyCalledViaReflection), new Type[0])]
public static void TestIfElse (int i)
{
Type myType;
@@ -773,9 +725,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
{ }
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string) },
- typeof (BaseClass), nameof (BaseClass.OnlyCalledViaReflection), new Type[0])]
public static void TestMethodInBaseType ()
{
var method = typeof (DerivedClass).GetMethod ("OnlyCalledViaReflection");
@@ -798,9 +747,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (IgnoreCaseBindingFlags), nameof (IgnoreCaseBindingFlags.OnlyCalledViaReflection), new Type[0])]
public static void TestIgnoreCaseBindingFlags ()
{
var method = typeof (IgnoreCaseBindingFlags).GetMethod ("onlycalledviareflection", BindingFlags.IgnoreCase | BindingFlags.Public);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/MethodsUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/MethodsUsedViaReflection.cs
index 5658a1a99..fcede014b 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/MethodsUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/MethodsUsedViaReflection.cs
@@ -27,21 +27,18 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestGetMethods ()
{
var methods = typeof (MethodsUsedViaReflection).GetMethods ();
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestBindingFlags ()
{
var methods = typeof (TestBindingClass).GetMethods (BindingFlags.Static | BindingFlags.Public);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestUnknownBindingFlags (BindingFlags bindingFlags)
{
// Since the binding flags are not known linker should mark all methods on the type
@@ -49,7 +46,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNullType ()
{
Type type = null;
@@ -63,8 +59,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetMethods), new Type[] { typeof (BindingFlags) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetMethods" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetMethods")]
static void TestDataFlowType ()
{
Type type = FindType ();
@@ -72,14 +67,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestDataFlowWithAnnotation ([KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))][DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type type)
{
var methods = type.GetMethods (BindingFlags.Public | BindingFlags.Static);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIfElse (int i)
{
Type myType;
@@ -94,7 +87,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIgnoreCaseBindingFlags ()
{
var methods = typeof (IgnoreCaseClass).GetMethods (BindingFlags.IgnoreCase | BindingFlags.Public);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/NestedTypeUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/NestedTypeUsedViaReflection.cs
index 2700a8793..66256ef78 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/NestedTypeUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/NestedTypeUsedViaReflection.cs
@@ -8,6 +8,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
+ [ExpectedNoWarnings]
public class NestedTypeUsedViaReflection
{
public static void Main ()
@@ -28,9 +29,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
public static class NestedType { }
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetNestedType), new Type[] { typeof (string) },
- typeof (NestedTypeUsedViaReflection.NestedType), null, (Type[]) null)]
static void TestByName ()
{
_ = typeof (NestedTypeUsedViaReflection).GetNestedType (nameof (NestedType));
@@ -55,15 +53,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
protected static class ProtectedNestedType { }
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetNestedType), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (NestedTypeUsedViaReflection.PrivateNestedType), null, (Type[]) null)]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetNestedType), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (NestedTypeUsedViaReflection.PublicNestedType), null, (Type[]) null)]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetNestedType), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (NestedTypeUsedViaReflection.ProtectedNestedType), null, (Type[]) null)]
static void TestByBindingFlags ()
{
_ = typeof (NestedTypeUsedViaReflection).GetNestedType (nameof (PrivateNestedType), BindingFlags.NonPublic);
@@ -72,9 +61,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetNestedType), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (UnknownBindingFlags.PublicNestedType), null, (Type[]) null)]
static void TestByUnknownBindingFlags (BindingFlags bindingFlags)
{
// Since the binding flags are not known linker should mark all nested types on the type
@@ -82,9 +68,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetNestedType), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (UnknownBindingFlagsAndName.PublicNestedType), null, (Type[]) null)]
static void TestByUnknownBindingFlagsAndName (BindingFlags bindingFlags, string name)
{
// Since the binding flags and name are not known linker should mark all nested types on the type
@@ -105,9 +88,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetNestedType), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (IgnoreCaseClass.IgnoreCasePublicNestedType), null, (Type[]) null)]
static void TestIgnoreCaseBindingFlags ()
{
_ = typeof (IgnoreCaseClass).GetNestedType ("ignorecasepublicnestedtype", BindingFlags.IgnoreCase | BindingFlags.Public);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/NestedTypesUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/NestedTypesUsedViaReflection.cs
index 46c490a29..4d8683aed 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/NestedTypesUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/NestedTypesUsedViaReflection.cs
@@ -9,6 +9,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
+ [ExpectedNoWarnings]
public class NestedTypesUsedViaReflection
{
public static void Main ()
@@ -27,7 +28,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
public static class NestedType { }
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestGetNestedTypes ()
{
_ = typeof (NestedTypesUsedViaReflection).GetNestedType (nameof (NestedType));
@@ -43,14 +43,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
protected static class ProtectedNestedType { }
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestByBindingFlags ()
{
_ = typeof (NestedTypesUsedViaReflection).GetNestedTypes (BindingFlags.Public);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestByUnknownBindingFlags (BindingFlags bindingFlags)
{
// Since the binding flags are not known linker should mark all nested types on the type
@@ -58,7 +56,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNullType ()
{
Type type = null;
@@ -71,8 +68,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
return null;
}
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetNestedTypes), new Type[] { typeof (BindingFlags) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetNestedTypes" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetNestedTypes")]
[Kept]
static void TestDataFlowType ()
{
@@ -81,14 +77,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestDataFlowWithAnnotation ([KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))][DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicNestedTypes)] Type type)
{
_ = type.GetNestedTypes (BindingFlags.Public | BindingFlags.Static);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIgnoreCaseBindingFlags ()
{
_ = typeof (IgnoreCaseClass).GetNestedTypes (BindingFlags.IgnoreCase | BindingFlags.Public);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/PropertiesUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/PropertiesUsedViaReflection.cs
index 4f8346b7c..2254d93b6 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/PropertiesUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/PropertiesUsedViaReflection.cs
@@ -28,21 +28,18 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestGetProperties ()
{
var properties = typeof (PropertiesUsedViaReflection).GetProperties ();
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestBindingFlags ()
{
var properties = typeof (BindingFlagsTest).GetProperties (BindingFlags.Public | BindingFlags.Static);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestUnknownBindingFlags (BindingFlags bindingFlags)
{
// Since the binding flags are not known linker should mark all properties on the type
@@ -50,14 +47,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestPropertiesOfArray ()
{
var properties = typeof (int[]).GetProperties (BindingFlags.Public);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNullType ()
{
Type type = null;
@@ -71,8 +66,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetProperties), new Type[] { typeof (BindingFlags) },
- messageCode: "IL2075", message: new string[] { "GetProperties" })]
+ [ExpectedWarning ("IL2075", "GetProperties")]
static void TestDataFlowType ()
{
Type type = FindType ();
@@ -80,14 +74,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestDataFlowWithAnnotation ([KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))][DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicProperties)] Type type)
{
var properties = type.GetProperties (BindingFlags.Public | BindingFlags.Static);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIfElse (int i)
{
Type myType;
@@ -100,21 +92,18 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIgnoreCaseBindingFlags ()
{
var properties = typeof (IgnoreCaseBindingFlagsClass).GetProperties (BindingFlags.IgnoreCase | BindingFlags.Public);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIgnorableBindingFlags ()
{
var properties = typeof (ExactBindingBindingFlagsClass).GetProperties (BindingFlags.Public | BindingFlags.ExactBinding);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestUnsupportedBindingFlags ()
{
var properties = typeof (ChangeTypeBindingFlagsClass).GetProperties (BindingFlags.Public | BindingFlags.SuppressChangeType);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs
index 4004e894b..bdd671987 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs
@@ -6,6 +6,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupCSharpCompilerToUse ("csc")]
+ [ExpectedNoWarnings]
[SetupLinkerArgument ("--disable-opt", "unreachablebodies")]
public class PropertyUsedViaReflection
{
@@ -33,9 +34,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string) },
- typeof (PropertyUsedViaReflection), nameof (PropertyUsedViaReflection.OnlyUsedViaReflection), (Type[]) null)]
static void TestGetterAndSetter ()
{
var property = typeof (PropertyUsedViaReflection).GetProperty ("OnlyUsedViaReflection");
@@ -51,9 +49,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string) },
- typeof (PropertyUsedViaReflection), nameof (PropertyUsedViaReflection.SetterOnly), (Type[]) null)]
static void TestSetterOnly ()
{
var property = typeof (PropertyUsedViaReflection).GetProperty ("SetterOnly");
@@ -61,9 +56,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string) },
- typeof (PropertyUsedViaReflection), nameof (PropertyUsedViaReflection.GetterOnly), (Type[]) null)]
static void TestGetterOnly ()
{
var property = typeof (PropertyUsedViaReflection).GetProperty ("GetterOnly");
@@ -71,9 +63,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (BindingFlagsTest), nameof (BindingFlagsTest.PublicProperty), (Type[]) null)]
static void TestBindingFlags ()
{
var property = typeof (BindingFlagsTest).GetProperty ("PublicProperty", BindingFlags.Public);
@@ -81,9 +70,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (UnknownBindingFlags), nameof (UnknownBindingFlags.SomeProperty), (Type[]) null)]
static void TestUnknownBindingFlags (BindingFlags bindingFlags)
{
// Since the binding flags are not known linker should mark all properties on the type
@@ -92,9 +78,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (UnknownBindingFlagsAndName), nameof (UnknownBindingFlagsAndName.SomeProperty), (Type[]) null)]
static void TestUnknownBindingFlagsAndName (BindingFlags bindingFlags, string name)
{
// Since the binding flags and name are not known linker should mark all properties on the type
@@ -121,9 +104,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string) },
- typeof (Array), nameof (Array.LongLength))]
static void TestPropertyOfArray ()
{
var property = typeof (int[]).GetProperty ("LongLength");
@@ -144,8 +124,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetProperty" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetProperty")]
static void TestDataFlowType ()
{
Type type = FindType ();
@@ -153,18 +132,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string) },
- typeof (IfClass), nameof (IfClass.SetterOnly), (Type[]) null)]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string) },
- typeof (IfClass), nameof (IfClass.GetterOnly), (Type[]) null)]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string) },
- typeof (ElseClass), nameof (ElseClass.SetterOnly), (Type[]) null)]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string) },
- typeof (ElseClass), nameof (ElseClass.GetterOnly), (Type[]) null)]
static void TestIfElse (int i)
{
Type myType;
@@ -183,18 +150,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string) },
- typeof (BaseClass), nameof (BaseClass.GetterSetterOnBaseClass), (Type[]) null)]
static void TestPropertyInBaseType ()
{
var property = typeof (DerivedClass).GetProperty ("GetterSetterOnBaseClass");
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (IgnoreCaseBindingFlagsClass), nameof (IgnoreCaseBindingFlagsClass.SetterOnly), (Type[]) null)]
static void TestIgnoreCaseBindingFlags ()
{
var property = typeof (IgnoreCaseBindingFlagsClass).GetProperty ("setteronly", BindingFlags.IgnoreCase | BindingFlags.Public);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/RunClassConstructorUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/RunClassConstructorUsedViaReflection.cs
index e4670746c..0744577ec 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/RunClassConstructorUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/RunClassConstructorUsedViaReflection.cs
@@ -7,6 +7,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupCSharpCompilerToUse ("csc")]
+ [ExpectedNoWarnings]
public class RunClassConstructorUsedViaReflection
{
public static void Main ()
@@ -20,7 +21,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestRunClassConstructor ()
{
RuntimeHelpers.RunClassConstructor (typeof (OnlyUsedViaReflection).TypeHandle);
@@ -33,7 +33,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNull ()
{
Type type = null;
@@ -47,8 +46,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (RuntimeHelpers), nameof (RuntimeHelpers.RunClassConstructor), new Type[] { typeof (RuntimeTypeHandle) },
- messageCode: "IL2059", message: new string[] { "RunClassConstructor" })]
+ [ExpectedWarning ("IL2059", nameof (RuntimeHelpers) + "." + nameof (RuntimeHelpers.RunClassConstructor))]
static void TestDataFlowType ()
{
@@ -57,10 +55,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
- [UnrecognizedReflectionAccessPattern (typeof (RuntimeHelpers), nameof (RuntimeHelpers.RunClassConstructor), new Type[] { typeof (RuntimeTypeHandle) },
- messageCode: "IL2059")]
-
+ [ExpectedWarning ("IL2059", nameof (RuntimeHelpers) + "." + nameof (RuntimeHelpers.RunClassConstructor))]
static void TestIfElseUsingRuntimeTypeHandle (int i)
{
RuntimeTypeHandle myType;
@@ -75,7 +70,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIfElseUsingType (int i)
{
Type myType;
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/RuntimeReflectionExtensionsCalls.cs b/test/Mono.Linker.Tests.Cases/Reflection/RuntimeReflectionExtensionsCalls.cs
index 068975d4c..6d71c7ad8 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/RuntimeReflectionExtensionsCalls.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/RuntimeReflectionExtensionsCalls.cs
@@ -6,6 +6,7 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions;
namespace Mono.Linker.Tests.Cases.Reflection
{
#pragma warning disable 67 // The event {event} is not used
+ [ExpectedNoWarnings]
public class RuntimeReflectionExtensionsCalls
{
public static void Main ()
@@ -19,8 +20,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
#region GetRuntimeEvent
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (RuntimeReflectionExtensions), nameof (RuntimeReflectionExtensions.GetRuntimeEvent),
- new Type[] { typeof (Type), typeof (string) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (RuntimeReflectionExtensions) + "." + nameof (RuntimeReflectionExtensions.GetRuntimeEvent))]
public static void TestGetRuntimeEvent ()
{
typeof (ClassWithKeptMembers).GetRuntimeEvent ("PublicEvent");
@@ -28,14 +28,13 @@ namespace Mono.Linker.Tests.Cases.Reflection
typeof (ClassWithUnkeptMembers).GetRuntimeEvent ("ProtectedEvent");
GetClassWithEvent ().GetRuntimeEvent ("This string will not be reached");
typeof (Derived).GetRuntimeEvent ("Event");
- GetUnknownType ().GetRuntimeEvent (GetUnknownString ()); // UnrecognizedReflectionAccessPattern
+ GetUnknownType ().GetRuntimeEvent (GetUnknownString ()); // IL2072
}
#endregion
#region GetRuntimeField
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (RuntimeReflectionExtensions), nameof (RuntimeReflectionExtensions.GetRuntimeField),
- new Type[] { typeof (Type), typeof (string) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (RuntimeReflectionExtensions) + "." + nameof (RuntimeReflectionExtensions.GetRuntimeField))]
public static void TestGetRuntimeField ()
{
typeof (ClassWithKeptMembers).GetRuntimeField ("PublicField");
@@ -43,14 +42,13 @@ namespace Mono.Linker.Tests.Cases.Reflection
typeof (ClassWithUnkeptMembers).GetRuntimeField ("ProtectedField");
GetClassWithField ().GetRuntimeField ("This string will not be reached");
typeof (Derived).GetRuntimeField ("Field");
- GetUnknownType ().GetRuntimeField (GetUnknownString ()); // UnrecognizedReflectionAccessPattern
+ GetUnknownType ().GetRuntimeField (GetUnknownString ()); // IL2072
}
#endregion
#region GetRuntimeMethod
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (RuntimeReflectionExtensions), nameof (RuntimeReflectionExtensions.GetRuntimeMethod),
- new Type[] { typeof (Type), typeof (string), typeof (Type[]) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (RuntimeReflectionExtensions) + "." + nameof (RuntimeReflectionExtensions.GetRuntimeMethod))]
public static void TestGetRuntimeMethod ()
{
typeof (ClassWithKeptMembers).GetRuntimeMethod ("PublicMethod", Type.EmptyTypes);
@@ -58,14 +56,13 @@ namespace Mono.Linker.Tests.Cases.Reflection
typeof (ClassWithUnkeptMembers).GetRuntimeMethod ("ProtectedMethod", Type.EmptyTypes);
GetClassWithMethod ().GetRuntimeMethod ("This string will not be reached", Type.EmptyTypes);
typeof (Derived).GetRuntimeMethod ("Method", Type.EmptyTypes);
- GetUnknownType ().GetRuntimeMethod (GetUnknownString (), Type.EmptyTypes); // UnrecognizedReflectionAccessPattern
+ GetUnknownType ().GetRuntimeMethod (GetUnknownString (), Type.EmptyTypes); // IL2072
}
#endregion
#region GetRuntimeProperty
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (RuntimeReflectionExtensions), nameof (RuntimeReflectionExtensions.GetRuntimeProperty),
- new Type[] { typeof (Type), typeof (string) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (RuntimeReflectionExtensions) + "." + nameof (RuntimeReflectionExtensions.GetRuntimeProperty))]
public static void TestGetRuntimeProperty ()
{
typeof (ClassWithKeptMembers).GetRuntimeProperty ("PublicProperty");
@@ -73,7 +70,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
typeof (ClassWithUnkeptMembers).GetRuntimeProperty ("ProtectedProperty");
GetClassWithProperty ().GetRuntimeProperty ("This string will not be reached");
typeof (Derived).GetRuntimeProperty ("Property");
- GetUnknownType ().GetRuntimeProperty (GetUnknownString ()); // UnrecognizedReflectionAccessPattern
+ GetUnknownType ().GetRuntimeProperty (GetUnknownString ()); // IL2072
}
#endregion
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs
index 0f660e6ed..8cab53e83 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs
@@ -47,7 +47,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void TestNull ()
{
const string reflectionTypeKeptString = null;
@@ -133,9 +132,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
public class AType { }
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetType), new Type[] { typeof (string), typeof (bool) },
- typeof (AType), null, (Type[]) null)]
public static void TestType ()
{
const string reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+AType";
@@ -267,7 +263,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
public class CaseInsensitive { }
[Kept]
- [ExpectedWarning ("IL2096", "'System.Type.GetType(String,Boolean,Boolean)'")]
+ [ExpectedWarning ("IL2096", "'System.Type.GetType(String, Boolean, Boolean)'")]
static void TestTypeUsingCaseInsensitiveFlag ()
{
const string reflectionTypeKeptString = "mono.linker.tests.cases.reflection.TypeUsedViaReflection+CaseInsensitive, test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null";
@@ -277,7 +273,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
public class CaseUnknown { }
[Kept]
- [ExpectedWarning ("IL2096", "'System.Type.GetType(String,Boolean,Boolean)'")]
+ [ExpectedWarning ("IL2096", "'System.Type.GetType(String, Boolean, Boolean)'")]
static void TestTypeUsingCaseUnknownByTheLinker ()
{
bool hideCase = GetCase ();
@@ -297,7 +293,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
public class CaseUnknown2 { }
[Kept]
- [ExpectedWarning ("IL2096", "'System.Type.GetType(String,Boolean,Boolean)'")]
+ [ExpectedWarning ("IL2096", "'System.Type.GetType(String, Boolean, Boolean)'")]
static void TestTypeUsingCaseUnknownByTheLinker2 ()
{
const string reflectionTypeKeptString = "mono.linker.tests.cases.reflection.TypeUsedViaReflection+CaseUnknown2, test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null";
@@ -328,7 +324,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
public class OverloadWith5ParametersWithIgnoreCase { }
[Kept]
- [ExpectedWarning ("IL2096", "'System.Type.GetType(String,Func<AssemblyName,Assembly>,Func<Assembly,String,Boolean,Type>,Boolean,Boolean)'")]
+ [ExpectedWarning ("IL2096", "'System.Type.GetType(String, Func<AssemblyName,Assembly>, Func<Assembly,String,Boolean,Type>, Boolean, Boolean)'")]
static void TestTypeOverloadWith5ParametersWithIgnoreCase ()
{
const string reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+OverloadWith5ParametersWithIgnoreCase";
@@ -361,15 +357,15 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [ExpectedWarning ("IL2026", "'System.Reflection.Assembly.GetType(String,Boolean)'")]
- [ExpectedWarning ("IL2057", "'System.Type.GetType(String,Boolean)'")]
+ [ExpectedWarning ("IL2026", "'System.Reflection.Assembly.GetType(String, Boolean)'")]
+ [ExpectedWarning ("IL2057", "'System.Type.GetType(String, Boolean)'")]
static Type GetTypeFromAssembly (Assembly assembly, string name, bool caseSensitive)
{
return assembly == null ? Type.GetType (name, caseSensitive) : assembly.GetType (name, caseSensitive);
}
[Kept]
- [ExpectedWarning ("IL2096", "'System.Type.GetType(String,Boolean,Boolean)'")]
+ [ExpectedWarning ("IL2096", "'System.Type.GetType(String, Boolean, Boolean)'")]
static void TestUnkownIgnoreCase3Params (int num)
{
const string reflectionTypeKeptString = "mono.linker.tests.cases.reflection.TypeUsedViaReflection+CaseUnknown2, test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null";
@@ -378,7 +374,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [ExpectedWarning ("IL2096", "'System.Type.GetType(String,Func<AssemblyName,Assembly>,Func<Assembly,String,Boolean,Type>,Boolean,Boolean)'")]
+ [ExpectedWarning ("IL2096", "'System.Type.GetType(String, Func<AssemblyName,Assembly>, Func<Assembly,String,Boolean,Type>, Boolean, Boolean)'")]
static void TestUnkownIgnoreCase5Params (int num)
{
const string reflectionTypeKeptString = "mono.linker.tests.cases.reflection.TypeUsedViaReflection+CaseUnknown2, test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null";
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeDoesntExist.cs b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeDoesntExist.cs
index ef69a23e7..3f6244c10 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeDoesntExist.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeDoesntExist.cs
@@ -5,7 +5,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupCSharpCompilerToUse ("csc")]
- [VerifyAllReflectionAccessPatternsAreValidated]
+ [ExpectedNoWarnings]
public class TypeUsedViaReflectionTypeDoesntExist
{
public static void Main ()
diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresAttributeMismatch.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresAttributeMismatch.cs
index e519cd9c4..1abc164d3 100644
--- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresAttributeMismatch.cs
+++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresAttributeMismatch.cs
@@ -285,9 +285,11 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
[RequiresUnreferencedCode ("Message")]
[RequiresAssemblyFiles ("Message")]
[RequiresDynamicCode ("Message")]
- [ExpectedWarning ("IL2046", "ExplicitImplementationClassWithRequires.Mono.Linker.Tests.Cases.RequiresCapability.RequiresAttributeMismatch.IBaseWithoutRequires.Method()", "IBaseWithoutRequires.Method()")]
- [ExpectedWarning ("IL3003", "ExplicitImplementationClassWithRequires.Mono.Linker.Tests.Cases.RequiresCapability.RequiresAttributeMismatch.IBaseWithoutRequires.Method()", "IBaseWithoutRequires.Method()", ProducedBy = ProducedBy.Analyzer)]
- [ExpectedWarning ("IL3051", "ExplicitImplementationClassWithRequires.Mono.Linker.Tests.Cases.RequiresCapability.RequiresAttributeMismatch.IBaseWithoutRequires.Method()", "IBaseWithoutRequires.Method()", ProducedBy = ProducedBy.Analyzer)]
+ // Linker member string format includes namespace of explicit interface method.
+ [ExpectedWarning ("IL2046", "ExplicitImplementationClassWithRequires.Mono.Linker.Tests.Cases.RequiresCapability.RequiresAttributeMismatch.IBaseWithoutRequires.Method()", "IBaseWithoutRequires.Method()", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2046", "ExplicitImplementationClassWithRequires.IBaseWithoutRequires.Method()", "IBaseWithoutRequires.Method()", ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL3003", "ExplicitImplementationClassWithRequires.IBaseWithoutRequires.Method()", "IBaseWithoutRequires.Method()", ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL3051", "IBaseWithoutRequires.Method()", "ExplicitImplementationClassWithRequires.IBaseWithoutRequires.Method()", ProducedBy = ProducedBy.Analyzer)]
void IBaseWithoutRequires.Method ()
{
}
@@ -356,9 +358,11 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class ExplicitImplementationClassWithoutRequires : IBaseWithRequires
{
- [ExpectedWarning ("IL2046", "IBaseWithRequires.Method()", "ExplicitImplementationClassWithoutRequires.Mono.Linker.Tests.Cases.RequiresCapability.RequiresAttributeMismatch.IBaseWithRequires.Method()")]
- [ExpectedWarning ("IL3003", "IBaseWithRequires.Method()", "ExplicitImplementationClassWithoutRequires.Mono.Linker.Tests.Cases.RequiresCapability.RequiresAttributeMismatch.IBaseWithRequires.Method()", ProducedBy = ProducedBy.Analyzer)]
- [ExpectedWarning ("IL3051", "IBaseWithRequires.Method()", "ExplicitImplementationClassWithoutRequires.Mono.Linker.Tests.Cases.RequiresCapability.RequiresAttributeMismatch.IBaseWithRequires.Method()", ProducedBy = ProducedBy.Analyzer)]
+ // Linker member string format includes namespace of explicit interface method.
+ [ExpectedWarning ("IL2046", "IBaseWithRequires.Method()", "ExplicitImplementationClassWithoutRequires.Mono.Linker.Tests.Cases.RequiresCapability.RequiresAttributeMismatch.IBaseWithRequires.Method()", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2046", "IBaseWithRequires.Method()", "ExplicitImplementationClassWithoutRequires.IBaseWithRequires.Method()", ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL3003", "IBaseWithRequires.Method()", "ExplicitImplementationClassWithoutRequires.IBaseWithRequires.Method()", ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL3051", "IBaseWithRequires.Method()", "ExplicitImplementationClassWithoutRequires.IBaseWithRequires.Method()", ProducedBy = ProducedBy.Analyzer)]
void IBaseWithRequires.Method ()
{
}
diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityReflectionAnalysisEnabled.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityReflectionAnalysisEnabled.cs
index 87b55c757..856c3d4a8 100644
--- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityReflectionAnalysisEnabled.cs
+++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityReflectionAnalysisEnabled.cs
@@ -8,6 +8,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.RequiresCapability
{
+ [ExpectedNoWarnings]
public class RequiresCapabilityReflectionAnalysisEnabled
{
[LogContains ("-- DynamicallyAccessedMembersEnabled --")]
@@ -24,7 +25,6 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
[Kept]
[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
[RequiresUnreferencedCode ("-- DynamicallyAccessedMembersEnabled --")]
- [RecognizedReflectionAccessPattern]
static void TestRequiresAttributeWithDynamicallyAccessedMembersEnabled ()
{
typeof (TypeWithPublicFieldsAccessed).RequiresPublicFields ();
@@ -42,7 +42,6 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
[Kept]
[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
[RequiresUnreferencedCode ("-- ReflectionPattern --")]
- [RecognizedReflectionAccessPattern]
static void TestRequiresAttributeWithReflectionPattern ()
{
typeof (TypeWithMethodAccessed).GetMethod ("PublicMethod");
@@ -60,7 +59,6 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
[Kept]
[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
[RequiresUnreferencedCode ("-- DynamicallyAccessedMembersOnGenericsEnabled --")]
- [RecognizedReflectionAccessPattern]
static void TestRequiresAttributeWithDynamicallyAccessedMembersOnGenericsEnabled ()
{
TypeRequiresPublicFields<TypeWithPublicFieldsForGenericType>.Method ();
@@ -104,13 +102,11 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[Kept]
- [ExpectedNoWarnings]
class TestRequiresAndDynamicallyAccessedMembers
{
[Kept]
[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
[RequiresUnreferencedCode ("--- RequiresAndPublicMethods ---")]
- [RecognizedReflectionAccessPattern]
static void RequiresAndPublicMethods (
[KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs
index 46f519aec..6020f7d86 100644
--- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs
+++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs
@@ -999,7 +999,6 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
Action _ = () => MethodWithRequires ();
}
- // The warning is currently not detected by roslyn analyzer since it doesn't analyze DAM yet
[ExpectedWarning ("IL2067", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("Suppress in body")]
[RequiresAssemblyFiles ("Suppress in body")]
@@ -1075,7 +1074,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
};
}
- // The warning is currently not detected by roslyn analyzer since it doesn't analyze DAM yet
+ // TODO: Fix the discrepancy between linker and analyzer
+ // https://github.com/dotnet/linker/issues/2350
[ExpectedWarning ("IL2077", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("Suppress in body")]
[RequiresAssemblyFiles ("Suppress in body")]
diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs
index 376309f8e..a9174a456 100644
--- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs
+++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnClass.cs
@@ -636,6 +636,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
static int privatefield;
}
+ // Analyzer doesn't implement DAM on type hierarchy yet
+ [ExpectedWarning ("IL2075", ProducedBy = ProducedBy.Analyzer)]
static void TestDAMOnTypeAccess (DAMAnnotatedClass instance)
{
instance.GetType ().GetField ("publicField");
@@ -787,6 +789,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
}
+ // Analyzer doesn't implement DAM on type hierarchy yet
+ [ExpectedWarning ("IL2075", ProducedBy = ProducedBy.Analyzer)]
static void TestDAMOnTypeAccess (DAMAnnotatedClass instance)
{
instance.GetType ().GetProperty ("publicProperty");