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:
authorVitek Karas <10670590+vitek-karas@users.noreply.github.com>2021-12-15 21:42:48 +0300
committerGitHub <noreply@github.com>2021-12-15 21:42:48 +0300
commit6e28469cb128a35b75f30392134af3f0d0b36774 (patch)
tree3374834e459503bef394af16918fe11c551b8b71 /test/Mono.Linker.Tests.Cases/DataFlow
parent5919fd8e62d9980a074c1d7d009ea789ef3585f0 (diff)
[feature/damAnalyzer] Remove reflection access patterns from tests (#2444)
Removes the `RecodnizedReflectionAccessPattern` and `UnrecognizedReflectionAccessPattern` attributes and all of the infrastructure for it. In the tests this is replaced by: * `ExpectedNoWarning` on the test level which makes sure we don't produce unexpected warnings (basically equivalent to `RecognizedReflecitonAccessPattern`. * `ExpectedWarning` to mark the places where warning should be generated - direct replacement for `UnrecognizedReflectionAccessPattern`. This change also removes some of the test-private helpers and replaces it with the `DataFlowTypeExtensions` helpers. This is mostly a mechanical change. This is part of the work to remove reflection access patterns from everywhere - in order to make the data flow logic sharable with the analyzer.
Diffstat (limited to 'test/Mono.Linker.Tests.Cases/DataFlow')
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/ApplyTypeAnnotations.cs1
-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.cs1
-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/FieldDataFlow.cs21
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs274
-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/IReflectDataflow.cs1
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/LocalDataFlow.cs178
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/LocalDataFlowKeptMembers.cs1
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/MemberTypes.cs5
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/MemberTypesAllOnCopyAssembly.cs2
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs97
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/MethodReturnParameterDataFlow.cs26
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs50
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs43
-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.cs57
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/UnresolvedMembers.cs1
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/VirtualMethodHierarchyDataflowAnnotationValidation.cs4
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/XmlAnnotations.cs91
27 files changed, 395 insertions, 640 deletions
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/ApplyTypeAnnotations.cs b/test/Mono.Linker.Tests.Cases/DataFlow/ApplyTypeAnnotations.cs
index f02ea1cba..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 ()
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 69d4e7959..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 ()
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/FieldDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs
index 30b520ff7..51d21f1f2 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs
@@ -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 ()
@@ -49,9 +50,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow
[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);
@@ -70,8 +71,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
_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 ();
@@ -94,8 +95,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
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);
@@ -116,8 +117,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
_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);
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs
index a765e85aa..50900b35a 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs
@@ -68,12 +68,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 ();
@@ -81,12 +76,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (T).RequiresNone ();
}
- [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);
@@ -95,7 +85,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
- [RecognizedReflectionAccessPattern]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)]
public static Type ReturnRequiresPublicFields ()
{
@@ -103,12 +92,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 ()
{
@@ -124,7 +108,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 ();
@@ -135,8 +119,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 ();
@@ -148,12 +132,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 ();
@@ -164,8 +146,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 ();
@@ -189,7 +171,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicMethods)] TBoth,
TNothing>
{
- [RecognizedReflectionAccessPattern]
public static void TestMultiple ()
{
typeof (TFields).RequiresPublicFields ();
@@ -202,7 +183,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 ();
@@ -210,7 +191,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 ();
@@ -218,7 +199,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (TMethods).RequiresNone ();
}
- [RecognizedReflectionAccessPattern]
public static void TestBoth ()
{
typeof (TBoth).RequiresPublicFields ();
@@ -226,8 +206,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 ();
@@ -236,7 +216,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
}
- [RecognizedReflectionAccessPattern]
static void TestBaseTypeGenericRequirements ()
{
new DerivedTypeWithInstantiatedGenericOnBase ();
@@ -247,14 +226,12 @@ namespace Mono.Linker.Tests.Cases.DataFlow
class GenericBaseTypeWithRequirements<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] T>
{
- [RecognizedReflectionAccessPattern]
public GenericBaseTypeWithRequirements ()
{
typeof (T).RequiresPublicFields ();
}
}
- [RecognizedReflectionAccessPattern]
class DerivedTypeWithInstantiatedGenericOnBase : GenericBaseTypeWithRequirements<TestType>
{
}
@@ -263,19 +240,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>
{
@@ -293,7 +268,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
class InterfaceImplementationTypeWithInstantiatedGenericOnBase : IGenericInterfaceTypeWithRequirements<TestType>
{
}
@@ -302,23 +276,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 ();
@@ -330,12 +301,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 ();
@@ -344,7 +313,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
}
- [RecognizedReflectionAccessPattern]
static void TestTypeGenericRequirementsOnMembers ()
{
// Basically just root everything we need to test
@@ -370,50 +338,43 @@ 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>))]
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> ();
@@ -428,27 +389,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>
{
@@ -463,7 +421,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> ()
{
@@ -472,7 +430,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> ()
{
@@ -481,8 +439,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (T).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 MethodRequiresNothing<T> ()
{
typeof (T).RequiresPublicFields ();
@@ -490,7 +448,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> ()
{
@@ -499,8 +457,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> ();
@@ -533,27 +491,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> ()
@@ -572,101 +523,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;
@@ -685,7 +625,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,
@@ -702,7 +641,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,
@@ -714,7 +653,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,
@@ -737,8 +676,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,
@@ -779,29 +718,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];
@@ -809,8 +744,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];
@@ -818,7 +752,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (GenericWithPublicFieldsArgument<>).MakeGenericType (types);
}
- [RecognizedReflectionAccessPattern]
static void TestNoArguments ()
{
typeof (TypeMakeGenericNoArguments).MakeGenericType ();
@@ -828,7 +761,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
static void TestWithRequirements ()
{
// Currently this is not analyzable since we don't track array elements.
@@ -836,14 +768,12 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (GenericWithPublicFieldsArgument<>).MakeGenericType (typeof (TestType));
}
- [RecognizedReflectionAccessPattern]
static void TestWithRequirementsFromParam (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] Type type)
{
typeof (GenericWithPublicFieldsArgument<>).MakeGenericType (type);
}
- [RecognizedReflectionAccessPattern]
static void TestWithRequirementsFromGenericParam<
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] T> ()
{
@@ -854,13 +784,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);
@@ -870,7 +798,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
static void TestWithMultipleArgumentsWithRequirements ()
{
typeof (GenericWithMultipleArgumentsWithRequirements<,>).MakeGenericType (typeof (TestType), typeof (TestType));
@@ -882,7 +809,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
static void TestWithNewConstraint ()
{
typeof (GenericWithNewConstraint<>).MakeGenericType (typeof (TestType));
@@ -892,7 +818,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
static void TestWithStructConstraint ()
{
typeof (GenericWithStructConstraint<>).MakeGenericType (typeof (TestType));
@@ -902,7 +827,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
static void TestWithUnmanagedConstraint ()
{
typeof (GenericWithUnmanagedConstraint<>).MakeGenericType (typeof (TestType));
@@ -912,7 +836,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
static void TestWithNullable ()
{
typeof (Nullable<>).MakeGenericType (typeof (TestType));
@@ -959,38 +882,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];
@@ -999,8 +917,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];
@@ -1011,8 +928,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];
@@ -1025,8 +941,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];
@@ -1036,7 +951,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
.MakeGenericMethod (types);
}
- [RecognizedReflectionAccessPattern]
static void TestWithNoArguments ()
{
typeof (MakeGenericMethod).GetMethod (nameof (NonGenericMethod), BindingFlags.Static | BindingFlags.NonPublic)
@@ -1046,7 +960,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)
@@ -1057,14 +970,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)
{
@@ -1080,15 +991,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)
@@ -1099,23 +1008,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];
@@ -1125,7 +1031,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
.MakeGenericMethod (types);
}
- [RecognizedReflectionAccessPattern]
static void TestWithConditionalGenericTypeSet (bool thirdParameterIsStruct)
{
Type[] types = new Type[3];
@@ -1147,21 +1052,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)
@@ -1169,7 +1071,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))
@@ -1177,7 +1078,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
// There are no requirements, so no warnings
- [RecognizedReflectionAccessPattern]
static void TestWithNoRequirementsWrongNumberOfTypeParameters ()
{
typeof (MakeGenericMethod).GetMethod (nameof (GenericWithNoRequirements))
@@ -1185,7 +1085,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
// There are no requirements, so no warnings
- [RecognizedReflectionAccessPattern]
static void TestWithNoRequirementsUnknownArrayElement ()
{
Type[] types = new Type[1];
@@ -1198,7 +1097,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
- [RecognizedReflectionAccessPattern]
static void TestWithMultipleArgumentsWithRequirements ()
{
typeof (MakeGenericMethod).GetMethod (nameof (GenericWithMultipleArgumentsWithRequirements), BindingFlags.Static | BindingFlags.NonPublic)
@@ -1211,7 +1109,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- [RecognizedReflectionAccessPattern]
static void TestWithNewConstraint ()
{
typeof (MakeGenericMethod).GetMethod (nameof (GenericWithNewConstraint), BindingFlags.Static | BindingFlags.NonPublic)
@@ -1223,7 +1120,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
var t = new T ();
}
- [RecognizedReflectionAccessPattern]
static void TestWithStructConstraint ()
{
typeof (MakeGenericMethod).GetMethod (nameof (GenericWithStructConstraint), BindingFlags.Static | BindingFlags.NonPublic)
@@ -1235,7 +1131,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
var t = new T ();
}
- [RecognizedReflectionAccessPattern]
static void TestWithUnmanagedConstraint ()
{
typeof (MakeGenericMethod).GetMethod (nameof (GenericWithUnmanagedConstraint), BindingFlags.Static | BindingFlags.NonPublic)
@@ -1248,19 +1143,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/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 e373f5c3b..2f0243938 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 ()
@@ -37,16 +42,12 @@ namespace Mono.Linker.Tests.Cases.DataFlow
TestBackwardsEdgeLoop ();
}
- [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 ();
@@ -55,40 +56,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;
@@ -97,27 +90,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;
@@ -135,15 +122,16 @@ 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
}
// Analyzer doesn't understand exceptional control flow yet (https://github.com/dotnet/linker/issues/2273)
- [ExpectedWarning ("IL2072", nameof (LocalDataFlow) + "." + nameof (RequirePublicFields) + "(String)",
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicFields) + "(String)",
nameof (LocalDataFlow) + "." + nameof (GetWithPublicMethods) + "()",
ProducedBy = ProducedBy.Trimmer)]
- [ExpectedWarning ("IL2072", nameof (LocalDataFlow) + "." + nameof (RequirePublicMethods) + "(String)",
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicMethods) + "(String)",
nameof (LocalDataFlow) + "." + nameof (GetWithPublicFields) + "()",
ProducedBy = ProducedBy.Trimmer)]
public static void TestBranchMergeTry ()
@@ -156,16 +144,17 @@ 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
}
// Analyzer doesn't understand exceptional control flow yet (https://github.com/dotnet/linker/issues/2273)
- [ExpectedWarning ("IL2072", nameof (LocalDataFlow) + "." + nameof (RequirePublicFields) + "(String)",
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicFields) + "(String)",
nameof (LocalDataFlow) + "." + nameof (GetWithPublicMethods) + "()",
ProducedBy = ProducedBy.Trimmer)]
- [ExpectedWarning ("IL2072", nameof (LocalDataFlow) + "." + nameof (RequirePublicMethods) + "(String)",
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicMethods) + "(String)",
nameof (LocalDataFlow) + "." + nameof (GetWithPublicFields) + "()",
ProducedBy = ProducedBy.Trimmer)]
public static void TestBranchMergeCatch ()
@@ -177,16 +166,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
}
// Analyzer doesn't understand exceptional control flow yet (https://github.com/dotnet/linker/issues/2273)
- [ExpectedWarning ("IL2072", nameof (LocalDataFlow) + "." + nameof (RequirePublicFields) + "(String)",
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicFields) + "(String)",
nameof (LocalDataFlow) + "." + nameof (GetWithPublicMethods) + "()",
ProducedBy = ProducedBy.Trimmer)]
- [ExpectedWarning ("IL2072", nameof (LocalDataFlow) + "." + nameof (RequirePublicMethods) + "(String)",
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicMethods) + "(String)",
nameof (LocalDataFlow) + "." + nameof (GetWithPublicFields) + "()",
ProducedBy = ProducedBy.Trimmer)]
public static void TestBranchMergeFinally ()
@@ -199,12 +189,13 @@ namespace Mono.Linker.Tests.Cases.DataFlow
} finally {
str = GetWithPublicFields ();
}
- RequirePublicFields (str); // warns for GetWithPublicMethods
- RequirePublicMethods (str); // warns for GetWithPublicFields
+
+ str.RequiresPublicFields (); // warns for GetWithPublicMethods
+ str.RequiresPublicMethods (); // warns for GetWithPublicFields
}
// Analyzer gets this right (no warning), but trimmer merges all branches going forward.
- [ExpectedWarning ("IL2072", nameof (LocalDataFlow) + "." + nameof (RequirePublicFields) + "(String)", "type",
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicFields) + "(String)",
ProducedBy = ProducedBy.Trimmer)]
public static void TestBranchGoto ()
{
@@ -212,25 +203,25 @@ namespace Mono.Linker.Tests.Cases.DataFlow
if (String.Empty.Length == 0)
goto End;
str = GetWithPublicFields ();
- RequirePublicFields (str); // produces a warning
+ str.RequiresPublicFields (); // produces a warning
End:
return;
}
// Analyzer gets this right (no warning), but trimmer merges all branches going forward.
- [ExpectedWarning ("IL2072", nameof (LocalDataFlow) + "." + nameof (RequirePublicFields) + "(String)", "type",
+ [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
+ str.RequiresPublicFields (); // produces a warning
}
}
// Analyzer gets this right (no warning), but trimmer merges all branches going forward.
- [ExpectedWarning ("IL2072", nameof (LocalDataFlow) + "." + nameof (RequirePublicFields) + "(String)", "type",
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicFields),
ProducedBy = ProducedBy.Trimmer)]
public static void TestBranchIfElse ()
{
@@ -238,20 +229,20 @@ namespace Mono.Linker.Tests.Cases.DataFlow
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
}
}
// Analyzer gets this right (no warning), but trimmer merges all branches going forward.
- [ExpectedWarning ("IL2072", nameof (LocalDataFlow) + "." + nameof (RequireNonPublicMethods) + "(String)", "type",
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresNonPublicMethods) + "(String)",
ProducedBy = ProducedBy.Trimmer)]
- [ExpectedWarning ("IL2072", nameof (LocalDataFlow) + "." + nameof (RequirePublicMethods) + "(String)", "type",
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicMethods) + "(String)",
ProducedBy = ProducedBy.Trimmer)]
- [ExpectedWarning ("IL2072", nameof (LocalDataFlow) + "." + nameof (RequirePublicConstructors) + "(String)", "type",
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicConstructors) + "(String)",
ProducedBy = ProducedBy.Trimmer)]
public static void TestBranchSwitch ()
{
@@ -259,25 +250,25 @@ namespace Mono.Linker.Tests.Cases.DataFlow
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;
}
}
// Analyzer doesn't understand exceptional control flow yet (https://github.com/dotnet/linker/issues/2273)
- [ExpectedWarning ("IL2072", nameof (LocalDataFlow) + "." + nameof (RequirePublicFields) + "(String)",
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicFields),
nameof (LocalDataFlow) + "." + nameof (GetWithPublicMethods) + "()",
ProducedBy = ProducedBy.Trimmer)]
public static void TestBranchTry ()
@@ -288,13 +279,13 @@ namespace Mono.Linker.Tests.Cases.DataFlow
throw null;
str = GetWithPublicFields ();
- RequirePublicFields (str); // warns for GetWithPublicMethods
+ str.RequiresPublicFields (); // warns for GetWithPublicMethods
} catch {
}
}
// Analyzer doesn't understand exceptional control flow yet (https://github.com/dotnet/linker/issues/2273)
- [ExpectedWarning ("IL2072", nameof (LocalDataFlow) + "." + nameof (RequirePublicFields) + "(String)",
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicFields),
nameof (LocalDataFlow) + "." + nameof (GetWithPublicMethods) + "()",
ProducedBy = ProducedBy.Trimmer)]
public static void TestBranchCatch ()
@@ -305,12 +296,12 @@ namespace Mono.Linker.Tests.Cases.DataFlow
throw null;
} catch {
str = GetWithPublicFields ();
- RequirePublicFields (str); // warns for GetWithPublicMethods
+ str.RequiresPublicFields (); // warns for GetWithPublicMethods
}
}
// Analyzer doesn't understand exceptional control flow yet (https://github.com/dotnet/linker/issues/2273)
- [ExpectedWarning ("IL2072", nameof (LocalDataFlow) + "." + nameof (RequirePublicFields) + "(String)",
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicFields),
nameof (LocalDataFlow) + "." + nameof (GetWithPublicMethods) + "()",
ProducedBy = ProducedBy.Trimmer)]
public static void TestBranchFinally ()
@@ -322,13 +313,12 @@ 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 (LocalDataFlow) + "." + nameof (RequirePublicMethods) + "(String)",
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicMethods) + "(String)",
nameof (LocalDataFlow) + "." + nameof (GetWithPublicFields) + "()",
ProducedBy = ProducedBy.Analyzer)]
public static void TestBackwardsEdgeLoop ()
@@ -340,13 +330,12 @@ 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 (LocalDataFlow) + "." + nameof (RequirePublicMethods) + "(String)",
+ [ExpectedWarning ("IL2072", nameof (DataFlowStringExtensions) + "." + nameof (DataFlowStringExtensions.RequiresPublicMethods) + "(String)",
nameof (LocalDataFlow) + "." + nameof (GetWithPublicFields) + "()",
ProducedBy = ProducedBy.Analyzer)]
public static void TestBackwardsEdgeGoto ()
@@ -354,7 +343,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
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:
@@ -362,29 +351,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
goto BackwardTarget;
}
- 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..f71f65b81 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/MemberTypes.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/MemberTypes.cs
@@ -12,8 +12,13 @@ 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
+ [ExpectedWarning ("IL2026", nameof (System.Delegate), 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
+ [ExpectedWarning ("IL2111", nameof (System.Delegate), 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 adda3650a..0d5936130 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
{
@@ -39,46 +41,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))]
@@ -121,24 +122,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 ();
}
// TODO: https://github.com/dotnet/linker/issues/2273
// (Dataflow analysis is not supported by the analyzer yet)
[ExpectedWarning ("IL2067",
- nameof (MethodParametersDataFlow) + "." + nameof (RequirePublicConstructors) + "(Type)",
- "type")]
+ nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors) + "(Type)",
+ "'type'")]
private void TwoAnnotatedParametersIntoOneValue (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
Type type,
@@ -146,50 +147,46 @@ 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.
[ExpectedWarning ("IL2062",
- nameof (MethodParametersDataFlow) + "." + nameof (RequirePublicParameterlessConstructor) + "(Type)",
- "type",
+ 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 ());
@@ -201,28 +198,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
- 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 e5721b35d..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)]
@@ -171,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)
{
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs
index 56c0844d4..6a7e8321a 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs
@@ -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,13 +83,13 @@ namespace Mono.Linker.Tests.Cases.DataFlow
return null;
}
- [RecognizedReflectionAccessPattern]
static void TestAnnotationOnNonTypeMethod ()
{
var t = new NonTypeType ();
t.GetMethod ("foo");
NonTypeType.StaticMethod ();
}
+
// 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'",
@@ -108,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 ();
@@ -117,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 ();
@@ -186,11 +180,9 @@ namespace System
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 ()
@@ -209,11 +201,9 @@ namespace System
_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 685b6a296..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 ()
@@ -48,7 +49,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
[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 ();
@@ -57,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 ();
@@ -66,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 ();
@@ -77,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 ();
@@ -92,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;
@@ -106,7 +105,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
Type PropertyPublicParameterlessConstructorWithExplicitAccessors {
- [RecognizedReflectionAccessPattern]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
get {
return _fieldWithPublicConstructors;
@@ -122,11 +120,8 @@ 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;
@@ -159,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 ();
@@ -172,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 ()
@@ -185,13 +180,12 @@ 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),
@@ -217,7 +211,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
}
- [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 ()
@@ -233,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;
}
@@ -260,6 +253,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow
ProducedBy = ProducedBy.Analyzer)]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
Type PropertyWithDifferentBackingFields {
+ [ExpectedWarning ("IL2078",
+ nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWithDifferentBackingFields) + ".get",
+ ProducedBy = ProducedBy.Trimmer)]
get {
return PropertyWithDifferentBackingFields_GetterField;
}
@@ -364,7 +360,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow
set { PropertyWithConflictingNoneAttributes_Field = value; }
}
- [RecognizedReflectionAccessPattern]
public void TestPropertyWithIndexerWithMatchingAnnotations ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)] Type myType)
{
var propclass = new PropertyWithIndexer ();
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 ea59e779d..097fa50f9 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 abe5aaada..c5915dd06 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 ()
@@ -45,22 +46,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 ();
@@ -72,9 +70,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 ();
@@ -86,9 +83,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 ();
@@ -100,23 +96,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 ();
@@ -128,43 +121,42 @@ 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 TestCombinationOfPublicsIsPropagated (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicProperties)] Type derivedType)
{
@@ -172,8 +164,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)
{
@@ -181,7 +173,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)
{
@@ -189,13 +181,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,
@@ -205,7 +197,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;
@@ -220,7 +212,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/UnresolvedMembers.cs b/test/Mono.Linker.Tests.Cases/DataFlow/UnresolvedMembers.cs
index e65c0e48c..13d964157 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 ()
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 ();
}
}
}