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
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.
-rw-r--r--test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs86
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Assertions/RecognizedReflectionAccessPatternAttribute.cs56
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Assertions/UnrecognizedReflectionAccessPatternAttribute.cs40
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Assertions/VerifyAllReflectionAccessPatternsAreHandledAttribute.cs12
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Helpers/DataFlowStringExtensions.cs42
-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
-rw-r--r--test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.cs43
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/ActivatorCreateInstance.cs33
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithSweptReferences.cs2
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/ConstructorUsedViaReflection.cs34
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/ConstructorsUsedViaReflection.cs9
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs22
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/EventsUsedViaReflection.cs12
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/ExpressionCallString.cs5
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/ExpressionFieldString.cs6
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/ExpressionNewType.cs15
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/ExpressionPropertyMethodInfo.cs13
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/ExpressionPropertyString.cs6
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs22
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/FieldsUsedViaReflection.cs11
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/MemberUsedViaReflection.cs12
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/MembersUsedViaReflection.cs9
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs58
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/MethodsUsedViaReflection.cs10
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/NestedTypeUsedViaReflection.cs22
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/NestedTypesUsedViaReflection.cs10
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/PropertiesUsedViaReflection.cs13
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs43
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/RunClassConstructorUsedViaReflection.cs12
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/RuntimeReflectionExtensionsCalls.cs21
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs4
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeDoesntExist.cs2
-rw-r--r--test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityReflectionAnalysisEnabled.cs6
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/LinkerCustomizations.cs2
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs303
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadataProvider.cs29
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/TestReflectionPatternRecorder.cs45
63 files changed, 513 insertions, 1592 deletions
diff --git a/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs b/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs
index b72b611bd..674d78156 100644
--- a/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs
+++ b/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs
@@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
-using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
@@ -175,8 +174,6 @@ namespace ILLink.RoslynAnalyzer.Tests
}
return true;
- case "UnrecognizedReflectionAccessPattern":
- return true;
default:
return false;
}
@@ -211,8 +208,6 @@ namespace ILLink.RoslynAnalyzer.Tests
return TryValidateExpectedWarningAttribute (attribute!, diagnostics, out matchIndex, out missingDiagnosticMessage);
case "LogContains":
return TryValidateLogContainsAttribute (attribute!, diagnostics, out matchIndex, out missingDiagnosticMessage);
- case "UnrecognizedReflectionAccessPattern":
- return TryValidateUnrecognizedReflectionAccessPatternAttribute (attribute!, diagnostics, out matchIndex, out missingDiagnosticMessage);
default:
throw new InvalidOperationException ($"Unsupported attribute type {attribute.Name}");
}
@@ -297,86 +292,5 @@ namespace ILLink.RoslynAnalyzer.Tests
foreach (var diagnostic in diagnosticMessages)
Assert.DoesNotContain (text, diagnostic.GetMessage ());
}
-
- private bool TryValidateUnrecognizedReflectionAccessPatternAttribute (AttributeSyntax attribute, List<Diagnostic> diagnostics, out int? matchIndex, out string? missingDiagnosticMessage)
- {
- missingDiagnosticMessage = null;
- matchIndex = null;
- var args = LinkerTestBase.GetAttributeArguments (attribute);
-
- MemberDeclarationSyntax sourceMember = attribute.Ancestors ().OfType<MemberDeclarationSyntax> ().First ();
- if (_semanticModel.GetDeclaredSymbol (sourceMember) is not ISymbol memberSymbol)
- return false;
-
- string sourceMemberName = memberSymbol!.GetDisplayName ();
- string expectedReflectionMemberMethodType = LinkerTestBase.GetStringFromExpression ((TypeOfExpressionSyntax) args["#0"], _semanticModel, ISymbolExtensions.ILLinkTypeDisplayFormat);
- string expectedReflectionMemberMethodName = LinkerTestBase.GetStringFromExpression (args["#1"], _semanticModel);
-
- var reflectionMethodParameters = new List<string> ();
- if (args.TryGetValue ("#2", out var reflectionMethodParametersExpr) || args.TryGetValue ("reflectionMethodParameters", out reflectionMethodParametersExpr)) {
- if (reflectionMethodParametersExpr is ArrayCreationExpressionSyntax arrayReflectionMethodParametersExpr) {
- foreach (var rmp in arrayReflectionMethodParametersExpr.Initializer!.Expressions) {
- var parameterStr = rmp.Kind () == SyntaxKind.TypeOfExpression
- ? LinkerTestBase.GetStringFromExpression ((TypeOfExpressionSyntax) rmp, _semanticModel, ISymbolExtensions.ILLinkMemberDisplayFormat)
- : LinkerTestBase.GetStringFromExpression (rmp, _semanticModel);
- reflectionMethodParameters.Add (parameterStr);
- }
- }
- }
-
- var expectedStringsInMessage = new List<string> ();
- if (args.TryGetValue ("#3", out var messageExpr) || args.TryGetValue ("message", out messageExpr)) {
- if (messageExpr is ArrayCreationExpressionSyntax arrayMessageExpr) {
- foreach (var m in arrayMessageExpr.Initializer!.Expressions)
- expectedStringsInMessage.Add (LinkerTestBase.GetStringFromExpression (m, _semanticModel));
- }
- }
-
- string expectedWarningCode = string.Empty;
- if (args.TryGetValue ("#4", out var messageCodeExpr) || args.TryGetValue ("messageCode", out messageCodeExpr)) {
- expectedWarningCode = LinkerTestBase.GetStringFromExpression (messageCodeExpr);
- Assert.True (expectedWarningCode.StartsWith ("IL"),
- $"The warning code specified in {messageCodeExpr.ToString ()} must start with the 'IL' prefix. Specified value: '{expectedWarningCode}'");
- }
-
- // Don't validate the return type becasue this is not included in the diagnostic messages.
-
- var sb = new StringBuilder ();
-
- // Format the member signature the same way Roslyn would since this is what will be included in the warning message.
- sb.Append (expectedReflectionMemberMethodType).Append (".").Append (expectedReflectionMemberMethodName);
- if (!expectedReflectionMemberMethodName.EndsWith (".get") &&
- !expectedReflectionMemberMethodName.EndsWith (".set") &&
- reflectionMethodParameters is not null)
- sb.Append ("(").Append (string.Join (", ", reflectionMethodParameters)).Append (")");
-
- var reflectionAccessPattern = sb.ToString ();
-
- for (int i = 0; i < diagnostics.Count; i++) {
- if (Matches (diagnostics[i])) {
- matchIndex = i;
- return true;
- }
- }
-
- missingDiagnosticMessage = $"Expected to find unrecognized reflection access pattern '{(expectedWarningCode == string.Empty ? "" : expectedWarningCode + " ")}" +
- $"{sourceMemberName}: Usage of {reflectionAccessPattern} unrecognized.";
- return false;
-
- bool Matches (Diagnostic diagnostic)
- {
- if (!string.IsNullOrEmpty (expectedWarningCode) && diagnostic.Id != expectedWarningCode)
- return false;
-
- // Don't check whether the message contains the source member name. Roslyn's diagnostics don't include the source
- // member as part of the message.
-
- foreach (var expectedString in expectedStringsInMessage)
- if (!diagnostic.GetMessage ().Contains (expectedString))
- return false;
-
- return diagnostic.GetMessage ().Contains (reflectionAccessPattern);
- }
- }
}
}
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RecognizedReflectionAccessPatternAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RecognizedReflectionAccessPatternAttribute.cs
deleted file mode 100644
index 4de5de43c..000000000
--- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/RecognizedReflectionAccessPatternAttribute.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-
-namespace Mono.Linker.Tests.Cases.Expectations.Assertions
-{
- [AttributeUsage (
- AttributeTargets.Method |
- AttributeTargets.Constructor |
- AttributeTargets.Class |
- AttributeTargets.Field |
- AttributeTargets.Property,
- AllowMultiple = true,
- Inherited = false)]
- public class RecognizedReflectionAccessPatternAttribute : BaseExpectedLinkedBehaviorAttribute
- {
- // The default .ctor has a special meaning - don't validate any specifically recognized reflection access patterns
- // but it will trigger the overall validation that all unrecognized patterns are expected.
- public RecognizedReflectionAccessPatternAttribute ()
- {
- }
-
- public RecognizedReflectionAccessPatternAttribute (Type reflectionMethodType, string reflectionMethodName, Type[] reflectionMethodParameters,
- Type accessedItemType, string accessedItemName, Type[] accessedItemParameters)
- {
- if (reflectionMethodType == null)
- throw new ArgumentException ("Value cannot be null or empty.", nameof (reflectionMethodType));
- if (reflectionMethodName == null)
- throw new ArgumentException ("Value cannot be null or empty.", nameof (reflectionMethodName));
- if (reflectionMethodParameters == null)
- throw new ArgumentException ("Value cannot be null or empty.", nameof (reflectionMethodParameters));
-
- if (accessedItemType == null)
- throw new ArgumentException ("Value cannot be null or empty.", nameof (accessedItemType));
- if (accessedItemName == null)
- throw new ArgumentException ("Value cannot be null or empty.", nameof (accessedItemName));
- }
-
- public RecognizedReflectionAccessPatternAttribute (Type reflectionMethodType, string reflectionMethodName, Type[] reflectionMethodParameters,
- Type accessedItemType, string accessedItemName, string[] accessedItemParameters = null)
- {
- if (reflectionMethodType == null)
- throw new ArgumentException ("Value cannot be null or empty.", nameof (reflectionMethodType));
- if (reflectionMethodName == null)
- throw new ArgumentException ("Value cannot be null or empty.", nameof (reflectionMethodName));
- if (reflectionMethodParameters == null)
- throw new ArgumentException ("Value cannot be null or empty.", nameof (reflectionMethodParameters));
-
- if (accessedItemType == null)
- throw new ArgumentException ("Value cannot be null or empty.", nameof (accessedItemType));
- if (accessedItemName == null)
- throw new ArgumentException ("Value cannot be null or empty.", nameof (accessedItemName));
- }
- }
-}
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/UnrecognizedReflectionAccessPatternAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/UnrecognizedReflectionAccessPatternAttribute.cs
deleted file mode 100644
index a59021e17..000000000
--- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/UnrecognizedReflectionAccessPatternAttribute.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-
-namespace Mono.Linker.Tests.Cases.Expectations.Assertions
-{
- [AttributeUsage (
- AttributeTargets.Method |
- AttributeTargets.Constructor |
- AttributeTargets.Class |
- AttributeTargets.Field |
- AttributeTargets.Property,
- AllowMultiple = true,
- Inherited = false)]
- public class UnrecognizedReflectionAccessPatternAttribute : BaseExpectedLinkedBehaviorAttribute
- {
- public UnrecognizedReflectionAccessPatternAttribute (
- Type reflectionMethodType,
- string reflectionMethodName,
- Type[] reflectionMethodParameters,
- string[] message = null,
- string messageCode = null,
- Type returnType = null,
- string genericParameter = null)
- {
- }
-
- public UnrecognizedReflectionAccessPatternAttribute (
- Type reflectionMethodType,
- string reflectionMethodName,
- string[] reflectionMethodParameters = null,
- string[] message = null,
- string messageCode = null,
- Type returnType = null,
- string genericParameter = null)
- {
- }
- }
-}
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/VerifyAllReflectionAccessPatternsAreHandledAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/VerifyAllReflectionAccessPatternsAreHandledAttribute.cs
deleted file mode 100644
index ae7debb02..000000000
--- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/VerifyAllReflectionAccessPatternsAreHandledAttribute.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using System;
-
-namespace Mono.Linker.Tests.Cases.Expectations.Assertions
-{
- [AttributeUsage (AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
- public class VerifyAllReflectionAccessPatternsAreValidatedAttribute : BaseExpectedLinkedBehaviorAttribute
- {
- public VerifyAllReflectionAccessPatternsAreValidatedAttribute ()
- {
- }
- }
-}
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Helpers/DataFlowStringExtensions.cs b/test/Mono.Linker.Tests.Cases.Expectations/Helpers/DataFlowStringExtensions.cs
new file mode 100644
index 000000000..1ff589928
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases.Expectations/Helpers/DataFlowStringExtensions.cs
@@ -0,0 +1,42 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Diagnostics.CodeAnalysis;
+
+namespace Mono.Linker.Tests.Cases.Expectations.Helpers
+{
+ public static class DataFlowStringExtensions
+ {
+ public static void RequiresAll ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] this string str) { }
+
+ public static void RequiresPublicConstructors ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)] this string str) { }
+
+ public static void RequiresPublicEvents ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicEvents)] this string str) { }
+
+ public static void RequiresPublicFields ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] this string str) { }
+
+ public static void RequiresPublicMethods ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] this string str) { }
+
+ public static void RequiresPublicNestedTypes ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicNestedTypes)] this string str) { }
+
+ public static void RequiresPublicParameterlessConstructor ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] this string str) { }
+
+ public static void RequiresPublicProperties ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicProperties)] this string str) { }
+
+ public static void RequiresNonPublicEvents ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicEvents)] this string str) { }
+
+ public static void RequiresNonPublicFields ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicFields)] this string str) { }
+
+ public static void RequiresNonPublicMethods ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicMethods)] this string str) { }
+
+ public static void RequiresNonPublicNestedTypes ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicNestedTypes)] this string str) { }
+
+ public static void RequiresNonPublicConstructors ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicConstructors)] this string str) { }
+
+ public static void RequiresNonPublicProperties ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicProperties)] this string str) { }
+
+ public static void RequiresInterfaces ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.Interfaces)] this string str) { }
+
+ public static void RequiresNone (this string str) { }
+ }
+}
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 ();
}
}
}
diff --git a/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.cs b/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.cs
index 07a2e654a..a798dfa51 100644
--- a/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.cs
+++ b/test/Mono.Linker.Tests.Cases/LinkAttributes/EmbeddedLinkAttributes.cs
@@ -4,6 +4,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Helpers;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.LinkAttributes
@@ -12,6 +13,7 @@ namespace Mono.Linker.Tests.Cases.LinkAttributes
[SetupCompileResource ("EmbeddedLinkAttributes.xml", "ILLink.LinkAttributes.xml")]
[IgnoreLinkAttributes (false)]
[RemovedResourceInAssembly ("test.exe", "ILLink.LinkAttributes.xml")]
+ [ExpectedNoWarnings]
class EmbeddedLinkAttributes
{
public static void Main ()
@@ -24,47 +26,22 @@ namespace Mono.Linker.Tests.Cases.LinkAttributes
Type _typeWithPublicParameterlessConstructor;
- [UnrecognizedReflectionAccessPattern (typeof (EmbeddedLinkAttributes), nameof (RequirePublicConstructors), new Type[] { typeof (Type) })]
- [UnrecognizedReflectionAccessPattern (typeof (EmbeddedLinkAttributes), nameof (RequireNonPublicConstructors), new Type[] { typeof (Type) })]
- [RecognizedReflectionAccessPattern]
+ [ExpectedWarning ("IL2077", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors))]
+ [ExpectedWarning ("IL2077", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors))]
private void ReadFromInstanceField ()
{
- RequirePublicParameterlessConstructor (_typeWithPublicParameterlessConstructor);
- RequirePublicConstructors (_typeWithPublicParameterlessConstructor);
- RequireNonPublicConstructors (_typeWithPublicParameterlessConstructor);
- }
- private static void RequirePublicParameterlessConstructor (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
- Type type)
- {
- }
-
- private static void RequirePublicConstructors (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
- Type type)
- {
- }
-
- private static void RequireNonPublicConstructors (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors)]
- Type type)
- {
+ _typeWithPublicParameterlessConstructor.RequiresPublicParameterlessConstructor ();
+ _typeWithPublicParameterlessConstructor.RequiresPublicConstructors ();
+ _typeWithPublicParameterlessConstructor.RequiresNonPublicConstructors ();
}
Type _typeWithPublicFields;
- [UnrecognizedReflectionAccessPattern (typeof (EmbeddedLinkAttributes), nameof (RequirePublicConstructors), new Type[] { typeof (Type) })]
- [RecognizedReflectionAccessPattern]
+ [ExpectedWarning ("IL2077", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors))]
private void ReadFromInstanceField2 ()
{
- RequirePublicConstructors (_typeWithPublicFields);
- RequirePublicFields (_typeWithPublicFields);
- }
-
- private static void RequirePublicFields (
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)]
- Type type)
- {
+ _typeWithPublicFields.RequiresPublicConstructors ();
+ _typeWithPublicFields.RequiresPublicFields ();
}
}
}
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/ActivatorCreateInstance.cs b/test/Mono.Linker.Tests.Cases/Reflection/ActivatorCreateInstance.cs
index 7eb814fe1..91ff5abb9 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/ActivatorCreateInstance.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/ActivatorCreateInstance.cs
@@ -8,6 +8,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupCSharpCompilerToUse ("csc")]
+ [ExpectedNoWarnings]
[KeptMember (".ctor()")]
public class ActivatorCreateInstance
{
@@ -165,8 +166,8 @@ namespace Mono.Linker.Tests.Cases.Reflection
public FromParameterOnStaticMethodTypeB (int arg) { }
}
- [UnrecognizedReflectionAccessPattern (typeof (Activator), nameof (Activator.CreateInstance), new Type[] { typeof (Type), typeof (object[]) }, messageCode: "IL2067")]
- [UnrecognizedReflectionAccessPattern (typeof (Activator), nameof (Activator.CreateInstance), new Type[] { typeof (Type), typeof (BindingFlags), typeof (Binder), typeof (object[]), typeof (CultureInfo) }, messageCode: "IL2067")]
+ [ExpectedWarning ("IL2067", nameof (Activator) + "." + nameof (Activator.CreateInstance) + "(Type, Object[])")]
+ [ExpectedWarning ("IL2067", nameof (Activator) + "." + nameof (Activator.CreateInstance), nameof (CultureInfo))]
[Kept]
private void FromParameterOnInstanceMethod (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
@@ -188,8 +189,8 @@ namespace Mono.Linker.Tests.Cases.Reflection
public FromParameterOnInstanceMethodType (int arg, int arg2) { }
}
- [UnrecognizedReflectionAccessPattern (typeof (Activator), nameof (Activator.CreateInstance), new Type[] { typeof (Type) }, messageCode: "IL2067")]
- [UnrecognizedReflectionAccessPattern (typeof (Activator), nameof (Activator.CreateInstance), new Type[] { typeof (Type), typeof (object[]) }, messageCode: "IL2067")]
+ [ExpectedWarning ("IL2067", nameof (Activator) + "." + nameof (Activator.CreateInstance) + "(Type)")]
+ [ExpectedWarning ("IL2067", nameof (Activator) + "." + nameof (Activator.CreateInstance) + "(Type, Object[])")]
[Kept]
private static void FromParameterWithNonPublicConstructors (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors)]
@@ -212,7 +213,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
private FromParameterWithNonPublicConstructorsType (int arg, int arg2) { }
}
- [UnrecognizedReflectionAccessPattern (typeof (Activator), nameof (Activator.CreateInstance), new Type[] { typeof (Type), typeof (BindingFlags), typeof (Binder), typeof (object[]), typeof (CultureInfo) }, messageCode: "IL2067")]
+ [ExpectedWarning ("IL2067", nameof (Activator) + "." + nameof (Activator.CreateInstance))]
[Kept]
private static void FromParameterWithPublicConstructors (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
@@ -319,16 +320,14 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Activator), nameof (Activator.CreateInstance), new Type[] { typeof (string), typeof (string) },
- messageCode: "IL2032", message: new string[] { "assemblyName" })]
+ [ExpectedWarning ("IL2032", nameof (Activator) + "." + nameof (Activator.CreateInstance), "assemblyName")]
private static void WithNullAssemblyName ()
{
Activator.CreateInstance (null, "Mono.Linker.Tests.Cases.Reflection.ActivatorCreateInstance+WithAssemblyNameParameterless1");
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Activator), nameof (Activator.CreateInstance), new Type[] { typeof (string), typeof (string) },
- messageCode: "IL2061", message: new string[] { "NonExistingAssembly" })]
+ [ExpectedWarning ("IL2061", nameof (Activator) + "." + nameof (Activator.CreateInstance), "NonExistingAssembly")]
private static void WithNonExistingAssemblyName ()
{
Activator.CreateInstance ("NonExistingAssembly", "Mono.Linker.Tests.Cases.Reflection.ActivatorCreateInstance+WithAssemblyNameParameterless1");
@@ -338,15 +337,13 @@ namespace Mono.Linker.Tests.Cases.Reflection
private static string _typeNameField;
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Activator), nameof (Activator.CreateInstance), new Type[] { typeof (string), typeof (string), typeof (object[]) },
- messageCode: "IL2032", message: new string[] { "typeName" })]
+ [ExpectedWarning ("IL2032", nameof (Activator) + "." + nameof (Activator.CreateInstance), "typeName")]
private static void WithAssemblyAndUnknownTypeName ()
{
Activator.CreateInstance ("test", _typeNameField, new object[] { });
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void WithAssemblyAndNonExistingTypeName ()
{
Activator.CreateInstance ("test", "NonExistingType", new object[] { });
@@ -381,7 +378,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void AppDomainCreateInstance ()
{
// Just a basic test that these are all recognized, we're not testing that it marks correctly as it has the exact same implementation
@@ -404,9 +400,9 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Assembly), nameof (Assembly.CreateInstance), new Type[] { typeof (string) }, messageCode: "IL2058")]
- [UnrecognizedReflectionAccessPattern (typeof (Assembly), nameof (Assembly.CreateInstance), new Type[] { typeof (string), typeof (bool) }, messageCode: "IL2058")]
- [UnrecognizedReflectionAccessPattern (typeof (Assembly), nameof (Assembly.CreateInstance), new Type[] { typeof (string), typeof (bool), typeof (BindingFlags), typeof (Binder), typeof (object[]), typeof (CultureInfo), typeof (object[]) }, messageCode: "IL2058")]
+ [ExpectedWarning ("IL2058", nameof (Assembly) + "." + nameof (Assembly.CreateInstance) + "(String)")]
+ [ExpectedWarning ("IL2058", nameof (Assembly) + "." + nameof (Assembly.CreateInstance) + "(String, Boolean)")]
+ [ExpectedWarning ("IL2058", nameof (Assembly) + "." + nameof (Assembly.CreateInstance), nameof (BindingFlags))]
private static void UnsupportedCreateInstance ()
{
typeof (ActivatorCreateInstance).Assembly.CreateInstance ("NonExistent");
@@ -428,7 +424,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestCreateInstanceOfTWithConcreteType ()
{
Activator.CreateInstance<TestCreateInstanceOfTWithConcreteTypeType> ();
@@ -448,7 +443,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestCreateInstanceOfTWithNewConstraint<T> () where T : new()
{
Activator.CreateInstance<T> ();
@@ -489,7 +483,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestCreateInstanceOfTWithDataflow<
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor),
KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] T> ()
@@ -507,14 +500,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestNullArgsOnKnownType ()
{
Activator.CreateInstance (typeof (TestNullArgsType), null);
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestNullArgsOnAnnotatedType (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor),
KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] Type type)
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithSweptReferences.cs b/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithSweptReferences.cs
index 5cecf5e5d..526376526 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithSweptReferences.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/AssemblyImportedViaReflectionWithSweptReferences.cs
@@ -5,6 +5,7 @@ using Mono.Linker.Tests.Cases.Reflection.Dependencies;
namespace Mono.Linker.Tests.Cases.Reflection
{
+ [ExpectedNoWarnings]
[SetupCSharpCompilerToUse ("csc")]
[SetupCompileBefore ("unusedreference.dll", new[] { "Dependencies/UnusedAssemblyDependency.cs" })]
[SetupCompileBefore ("reference.dll", new[] { "Dependencies/AssemblyDependency.cs" }, addAsReference: false)]
@@ -19,7 +20,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void AccessNonExistingTypeInAssembly ()
{
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/ConstructorUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/ConstructorUsedViaReflection.cs
index dde8f46f9..5c28deafe 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/ConstructorUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/ConstructorUsedViaReflection.cs
@@ -7,6 +7,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupCSharpCompilerToUse ("csc")]
+ [ExpectedNoWarnings]
public class ConstructorUsedViaReflection
{
public static void Main ()
@@ -58,9 +59,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (Type[]) },
- typeof (EmptyTypes), nameof (EmptyTypes), new Type[0])]
static void TestConstructorWithTypes_EmptyTypes ()
{
var constructor = typeof (EmptyTypes).GetConstructor (new Type[] { });
@@ -68,7 +66,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestConstructorWithTypes_NonEmptyTypes ()
{
var constructor = typeof (GetConstructor_Types).GetConstructor (new Type[] { typeof (int) });
@@ -76,7 +73,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestConstructorWithTypes_EmptyTypes_DataFlow (
[KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
@@ -87,8 +83,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (Type[]) }, messageCode: "IL2070")]
+ [ExpectedWarning ("IL2070", nameof (Type.GetConstructor))]
static void TestConstructorWithTypes_NonEmptyTypes_DataFlow (
[KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
@@ -123,9 +118,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (BindingFlags), typeof (Binder), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (KnownBindingFlags), nameof (KnownBindingFlags), new Type[0])]
public static void TestWithBindingFlags ()
{
var constructor = typeof (KnownBindingFlags).GetConstructor (BindingFlags.Public, GetNullValue ("some argument", 2, 3), new Type[] { }, new ParameterModifier[] { });
@@ -157,8 +149,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (BindingFlags), typeof (Binder), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (UnknownBindingFlags), nameof (UnknownBindingFlags), new Type[0])]
public static void TestWithUnknownBindingFlags (BindingFlags bindingFlags)
{
// Since the binding flags are not known linker should mark all constructors on the type
@@ -187,9 +177,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
{ }
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (BindingFlags), typeof (Binder), typeof (CallingConventions), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (GetConstructor_BindingAttr_Binder_CallConvention_Types_Modifiers), nameof (GetConstructor_BindingAttr_Binder_CallConvention_Types_Modifiers), new Type[0])]
public static void TestWithCallingConvention ()
{
var constructor = typeof (GetConstructor_BindingAttr_Binder_CallConvention_Types_Modifiers).GetConstructor (BindingFlags.Public, GetNullValue ("some argument", 2, 3), CallingConventions.HasThis, new Type[] { }, new ParameterModifier[] { });
@@ -236,9 +223,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (BindingFlags), typeof (Type[]) },
- typeof (GetConstructor_BindingAttr_Types), nameof (GetConstructor_BindingAttr_Types), new Type[0])]
static void TestWithBindingFlagsAndTypes_EmptyTypes ()
{
var constructor = typeof (GetConstructor_BindingAttr_Types).GetConstructor (BindingFlags.Public, new Type[] { });
@@ -246,7 +230,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestWithBindingFlagsAndTypes_NonEmptyTypes ()
{
var constructor = typeof (NonEmptyTypes).GetConstructor (BindingFlags.Public, new Type[] { typeof (TestType) });
@@ -254,7 +237,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestWithBindingFlagsAndTypes_EmptyTypes_DataFlow (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
[KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))]
@@ -264,8 +246,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (BindingFlags), typeof (Type[]) }, messageCode: "IL2070")]
+ [ExpectedWarning ("IL2070", nameof (Type.GetConstructor))]
static void TestWithBindingFlagsAndTypes_NonEmptyTypes_DataFlow (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
[KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))]
@@ -289,8 +270,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
return null;
}
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (Type[]) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetConstructor" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetConstructor")]
[Kept]
static void TestDataFlowType ()
{
@@ -342,12 +322,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (BindingFlags), typeof (Binder), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (IfConstructor), nameof (IfConstructor), new Type[0])]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetConstructor), new Type[] { typeof (BindingFlags), typeof (Binder), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (ElseConstructor), nameof (ElseConstructor), new Type[0])]
public static void TestIfElse (bool decision)
{
Type myType;
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/ConstructorsUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/ConstructorsUsedViaReflection.cs
index be6d2408b..78ed3dad1 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/ConstructorsUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/ConstructorsUsedViaReflection.cs
@@ -21,21 +21,18 @@ namespace Mono.Linker.Tests.Cases.Reflection
TestIfElse (true);
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestGetConstructors ()
{
var constructors = typeof (SimpleGetConstructors).GetConstructors ();
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestWithBindingFlags ()
{
var constructors = typeof (ConstructorsBindingFlags).GetConstructors (BindingFlags.Public | BindingFlags.Static);
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestWithUnknownBindingFlags (BindingFlags bindingFlags)
{
@@ -44,7 +41,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNullType ()
{
Type type = null;
@@ -57,8 +53,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
return null;
}
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetConstructors), new Type[] { typeof (BindingFlags) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetConstructors" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetConstructors")]
[Kept]
static void TestDataFlowType ()
{
@@ -67,14 +62,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestDataFlowWithAnnotation ([KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))][DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)] Type type)
{
var constructors = type.GetConstructors (BindingFlags.Public | BindingFlags.Static);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIfElse (bool decision)
{
Type myType;
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs
index 5f93cf879..5dbad0c58 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/EventUsedViaReflection.cs
@@ -6,6 +6,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupCSharpCompilerToUse ("csc")]
+ [ExpectedNoWarnings]
public class EventUsedViaReflection
{
public static void Main ()
@@ -31,9 +32,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetEvent), new Type[] { typeof (string) },
- typeof (Foo), nameof (Foo.Event), (Type[]) null)]
static void TestByName ()
{
var eventInfo = typeof (Foo).GetEvent ("Event");
@@ -111,8 +109,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetEvent), new Type[] { typeof (string) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetEvent" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetEvent")]
static void TestDataFlowType ()
{
Type type = FindType ();
@@ -120,15 +117,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetEvent), new Type[] { typeof (string) },
- typeof (IfClass), nameof (IfClass.IfEvent), (Type[]) null)]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetEvent), new Type[] { typeof (string) },
- typeof (IfClass), nameof (IfClass.ElseEvent), (Type[]) null)]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetEvent), new Type[] { typeof (string) },
- typeof (ElseClass), nameof (ElseClass.IfEvent), (Type[]) null)]
static void TestIfElse (int i)
{
Type myType;
@@ -147,9 +135,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetEvent), new Type[] { typeof (string) },
- typeof (BaseClass), nameof (BaseClass.PublicEventOnBase), (Type[]) null)]
static void TestEventInBaseType ()
{
typeof (DerivedClass).GetEvent ("ProtectedEventOnBase"); // Will not mark anything as it only works on public events
@@ -157,9 +142,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetEvent), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (IgnoreCaseBindingFlagsClass), nameof (IgnoreCaseBindingFlagsClass.PublicEvent), (Type[]) null)]
static void TestIgnoreCaseBindingFlags ()
{
typeof (IgnoreCaseBindingFlagsClass).GetEvent ("publicevent", BindingFlags.IgnoreCase | BindingFlags.Public);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/EventsUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/EventsUsedViaReflection.cs
index 0c2d15582..53a7494f6 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/EventsUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/EventsUsedViaReflection.cs
@@ -28,14 +28,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestGetEvents ()
{
var events = typeof (Foo).GetEvents ();
}
[Kept]
- [RecognizedReflectionAccessPattern]
// The event will not be kept as it's internal and the behavior of Type.GetEvents() is to only return public events
// But we don't mark it as unrecognized access pattern - we did recognize it fully, just didn't find the event being asked for
// The behavior of the code will not change by linking it:
@@ -47,14 +45,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestBindingFlags ()
{
var events = typeof (Bar).GetEvents (BindingFlags.NonPublic);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestUnknownBindingFlags (BindingFlags bindingFlags)
{
// Since the binding flags are not known linker should mark all events on the type
@@ -62,7 +58,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNullType ()
{
Type type = null;
@@ -76,8 +71,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetEvents), new Type[] { typeof (BindingFlags) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetEvents" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetEvents")]
static void TestDataFlowType ()
{
Type type = FindType ();
@@ -85,14 +79,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestDataFlowWithAnnotation ([KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))][DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicEvents)] Type type)
{
var events = type.GetEvents (BindingFlags.Public | BindingFlags.Static);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIfElse (int i)
{
Type myType;
@@ -105,14 +97,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIgnoreCaseBindingFlags ()
{
var events = typeof (IgnoreCaseBindingFlagsClass).GetEvents (BindingFlags.IgnoreCase | BindingFlags.Public);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestUnsupportedBindingFlags ()
{
var events = typeof (PutRefDispPropertyBindingFlagsClass).GetEvents (BindingFlags.PutRefDispProperty);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/ExpressionCallString.cs b/test/Mono.Linker.Tests.Cases/Reflection/ExpressionCallString.cs
index 699bb9d9d..bb89b436d 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/ExpressionCallString.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/ExpressionCallString.cs
@@ -118,13 +118,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
class TestUnknownType
{
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Expression), nameof (Expression.Call),
- new Type[] { typeof (Type), typeof (string), typeof (Type[]), typeof (Expression[]) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (Expression) + "." + nameof (Expression.Call))]
public static void Test ()
{
// Keep all methods of the type that made the call
Expression.Call (GetUnknownType (), "This string will not be reached", Type.EmptyTypes);
- // UnrecognizedReflectionAccessPattern
+ // IL2072
Expression.Call (TriggerUnrecognizedPattern (), "This string will not be reached", Type.EmptyTypes);
}
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/ExpressionFieldString.cs b/test/Mono.Linker.Tests.Cases/Reflection/ExpressionFieldString.cs
index 043172bc9..c2399e92c 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/ExpressionFieldString.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/ExpressionFieldString.cs
@@ -7,10 +7,10 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
[Reference ("System.Core.dll")]
+ [ExpectedNoWarnings]
public class ExpressionFieldString
{
- [UnrecognizedReflectionAccessPattern (typeof (Expression), nameof (Expression.Field),
- new Type[] { typeof (Expression), typeof (Type), typeof (string) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (Expression) + "." + nameof (Expression.Field))]
public static void Main ()
{
Expression.Field (Expression.Parameter (typeof (int), ""), typeof (ExpressionFieldString), "Field");
@@ -20,7 +20,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
UnknownType.Test ();
UnknownTypeNoAnnotation.Test ();
UnknownString.Test ();
- Expression.Field (null, GetType (), "This string will not be reached"); // UnrecognizedReflectionAccessPattern
+ Expression.Field (null, GetType (), "This string will not be reached"); // IL2072
}
[Kept]
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/ExpressionNewType.cs b/test/Mono.Linker.Tests.Cases/Reflection/ExpressionNewType.cs
index a137d122c..9e06ccb43 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/ExpressionNewType.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/ExpressionNewType.cs
@@ -8,6 +8,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
[Reference ("System.Core.dll")]
+ [ExpectedNoWarnings]
public class ExpressionNewType
{
public static void Main ()
@@ -25,11 +26,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
Expression.New (5 + 7 == 12 ? null : typeof (RemovedType));
}
- #region RecognizedReflectionAccessPatterns
- [RecognizedReflectionAccessPattern (
- typeof (Expression), nameof (Expression.New), new Type[] { typeof (Type) }, typeof (A), "A", new Type[0])]
- [RecognizedReflectionAccessPattern (
- typeof (Expression), nameof (Expression.New), new Type[] { typeof (Type) }, typeof (B), "B", new Type[0])]
[Kept]
static void Branch_SystemTypeValueNode (int i)
{
@@ -47,25 +43,22 @@ namespace Mono.Linker.Tests.Cases.Reflection
Expression.New (T);
}
- #endregion
- #region UnrecognizedReflectionAccessPatterns
- [UnrecognizedReflectionAccessPattern (typeof (Expression), nameof (Expression.New), new Type[] { typeof (Type) }, messageCode: "IL2067")]
+ [ExpectedWarning ("IL2067", nameof (Expression) + "." + nameof (Expression.New))]
[Kept]
static void Branch_MethodParameterValueNode (Type T)
{
Expression.New (T);
}
- [UnrecognizedReflectionAccessPattern (typeof (Expression), nameof (Expression.New), new Type[] { typeof (Type) }, messageCode: "IL2072")]
- [UnrecognizedReflectionAccessPattern (typeof (Expression), nameof (Expression.New), new Type[] { typeof (Type) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (Expression) + "." + nameof (Expression.New), "'System." + nameof (Type) + "." + nameof (Type.GetType))]
+ [ExpectedWarning ("IL2072", nameof (Expression) + "." + nameof (Expression.New), nameof (ExpressionNewType) + "." + nameof (ExpressionNewType.GetType))]
[Kept]
static void Branch_UnrecognizedPatterns ()
{
Expression.New (Type.GetType ("RemovedType"));
Expression.New (GetType ());
}
- #endregion
#region Helpers
[Kept]
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/ExpressionPropertyMethodInfo.cs b/test/Mono.Linker.Tests.Cases/Reflection/ExpressionPropertyMethodInfo.cs
index 8a0b2b3b0..b4d9613ae 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/ExpressionPropertyMethodInfo.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/ExpressionPropertyMethodInfo.cs
@@ -76,7 +76,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void Test ()
{
Expression<Func<int>> staticGetter = () => StaticProperty;
@@ -124,7 +123,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void Test ()
{
Expression.Property (null, typeof (PropertySetter).GetMethod ("set_StaticProperty"));
@@ -136,7 +134,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNull ()
{
MethodInfo mi = null;
@@ -144,16 +141,13 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (
- typeof (Expression), nameof (Expression.Property), new Type[] { typeof (Expression), typeof (MethodInfo) },
- messageCode: "IL2103")]
+ [ExpectedWarning ("IL2103", nameof (Expression) + "." + nameof (Expression.Property))]
static void TestNonPropertyMethod ()
{
Expression.Property (null, typeof (ExpressionPropertyMethodInfo).GetMethod (nameof (TestNonPropertyMethod), BindingFlags.NonPublic | BindingFlags.Static));
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNonExistentMethod ()
{
Expression.Property (null, typeof (ExpressionPropertyMethodInfo).GetMethod ("NonExistent"));
@@ -181,7 +175,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void Test (int p)
{
MethodInfo mi;
@@ -202,9 +195,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (
- typeof (Expression), nameof (Expression.Property), new Type[] { typeof (Expression), typeof (MethodInfo) },
- messageCode: "IL2103")]
+ [ExpectedWarning ("IL2103", nameof (Expression) + "." + nameof (Expression.Property))]
static void TestUnknownMethod (MethodInfo mi)
{
Expression.Property (null, mi);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/ExpressionPropertyString.cs b/test/Mono.Linker.Tests.Cases/Reflection/ExpressionPropertyString.cs
index 7379710bd..13de4491d 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/ExpressionPropertyString.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/ExpressionPropertyString.cs
@@ -9,10 +9,10 @@ namespace Mono.Linker.Tests.Cases.Reflection
// Explicitly use roslyn to try and get a compiler that supports defining a static property without a setter
[SetupCSharpCompilerToUse ("csc")]
[Reference ("System.Core.dll")]
+ [ExpectedNoWarnings]
public class ExpressionPropertyString
{
- [UnrecognizedReflectionAccessPattern (typeof (Expression), nameof (Expression.Property),
- new Type[] { typeof (Expression), typeof (Type), typeof (string) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (Expression) + "." + nameof (Expression.Property))]
public static void Main ()
{
Expression.Property (Expression.Parameter (typeof (int), ""), typeof (ExpressionPropertyString), "Property");
@@ -21,7 +21,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
Expression.Property (null, typeof (Derived), "PublicPropertyOnBase");
UnknownType.Test ();
UnknownString.Test ();
- Expression.Property (null, GetType (), "This string will not be reached"); // UnrecognizedReflectionAccessPattern
+ Expression.Property (null, GetType (), "This string will not be reached"); // IL2072
}
[Kept]
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs
index 94535adb1..c0fad7206 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/FieldUsedViaReflection.cs
@@ -6,6 +6,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupCSharpCompilerToUse ("csc")]
+ [ExpectedNoWarnings]
public class FieldUsedViaReflection
{
public static void Main ()
@@ -29,9 +30,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetField), new Type[] { typeof (string) },
- typeof (FieldUsedViaReflection), nameof (FieldUsedViaReflection.publicField), (Type[]) null)]
static void TestByName ()
{
var field = typeof (FieldUsedViaReflection).GetField ("publicField");
@@ -46,9 +44,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetField), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (Foo), nameof (Foo.field), (Type[]) null)]
static void TestNameBindingFlags ()
{
var field = typeof (Foo).GetField ("field", BindingFlags.Static);
@@ -106,8 +101,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetField), new Type[] { typeof (string) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetField" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetField")]
static void TestDataFlowType ()
{
Type type = FindType ();
@@ -115,12 +109,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetField), new Type[] { typeof (string) },
- typeof (IfClass), nameof (IfClass.ifField), (Type[]) null)]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetField), new Type[] { typeof (string) },
- typeof (ElseClass), nameof (ElseClass.elseField), (Type[]) null)]
static void TestIfElse (int i)
{
Type myType;
@@ -139,9 +127,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetField), new Type[] { typeof (string) },
- typeof (BaseClass), nameof (BaseClass.publicFieldOnBase), (Type[]) null)]
static void TestFieldInBaseType ()
{
var protectedField = typeof (DerivedClass).GetField ("protectedFieldOnBase"); // Will not be marked - only public fields work this way
@@ -149,9 +134,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetField), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (IgnoreCaseBindingFlagsClass), nameof (IgnoreCaseBindingFlagsClass.publicField), (Type[]) null)]
static void TestIgnoreCaseBindingFlags ()
{
var field = typeof (IgnoreCaseBindingFlagsClass).GetField ("publicfield", BindingFlags.IgnoreCase | BindingFlags.Public);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/FieldsUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/FieldsUsedViaReflection.cs
index 7f805345e..ab50a5dac 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/FieldsUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/FieldsUsedViaReflection.cs
@@ -24,21 +24,18 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestGetFields ()
{
var fields = typeof (FieldsUsedViaReflection).GetFields ();
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestBindingFlags ()
{
var fields = typeof (Foo).GetFields (BindingFlags.Public);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestUnknownBindingFlags (BindingFlags bindingFlags)
{
// Since the binding flags are not known linker should mark all fields on the type
@@ -46,7 +43,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNullType ()
{
Type type = null;
@@ -60,8 +56,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetFields), new Type[] { typeof (BindingFlags) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetFields" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetFields")]
static void TestDataFlowType ()
{
Type type = FindType ();
@@ -69,14 +64,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestDataFlowWithAnnotation ([KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))][DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] Type type)
{
var fields = type.GetFields (BindingFlags.Public | BindingFlags.Static);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIfElse (int i)
{
Type myType;
@@ -89,14 +82,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIgnoreCaseBindingFlags ()
{
var fields = typeof (IgnoreCaseBindingFlagsClass).GetFields (BindingFlags.IgnoreCase | BindingFlags.Public);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestUnsupportedBindingFlags ()
{
var fields = typeof (PutDispPropertyBindingFlagsClass).GetFields (BindingFlags.PutDispProperty);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/MemberUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/MemberUsedViaReflection.cs
index a73ed2d7a..828ce4d77 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/MemberUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/MemberUsedViaReflection.cs
@@ -7,6 +7,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupCSharpCompilerToUse ("csc")]
+ [ExpectedNoWarnings]
public class MemberUsedViaReflection
{
public static void Main ()
@@ -24,7 +25,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
TestIfElse (true);
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestWithName ()
{
@@ -32,21 +32,18 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestWithPrefixLookup ()
{
var members = typeof (PrefixLookupType).GetMember ("PrefixLookup*");
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestWithBindingFlags ()
{
var members = typeof (BindingFlagsType).GetMember ("PrefixLookup*", BindingFlags.Public | BindingFlags.NonPublic);
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestWithUnknownBindingFlags (BindingFlags bindingFlags)
{
@@ -54,7 +51,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
var members = typeof (UnknownBindingFlags).GetMember ("PrefixLookup*", bindingFlags);
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestWithMemberTypes ()
{
@@ -63,7 +59,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
var members = typeof (TestMemberTypes).GetMember ("PrefixLookup*", MemberTypes.Method, BindingFlags.Public);
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestNullType ()
{
@@ -77,8 +72,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
return null;
}
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetMember), new Type[] { typeof (string) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetMember" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetMember")]
[Kept]
static void TestDataFlowType ()
{
@@ -87,7 +81,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestDataFlowWithAnnotation ([KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors |
DynamicallyAccessedMemberTypes.PublicEvents |
@@ -100,7 +93,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIfElse (bool decision)
{
Type myType;
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/MembersUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/MembersUsedViaReflection.cs
index 5a7fe375e..8a20f7733 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/MembersUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/MembersUsedViaReflection.cs
@@ -21,21 +21,18 @@ namespace Mono.Linker.Tests.Cases.Reflection
TestIfElse (true);
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestGetMembers ()
{
var members = typeof (SimpleGetMembers).GetMembers ();
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestWithBindingFlags ()
{
var members = typeof (MembersBindingFlags).GetMembers (BindingFlags.Public);
}
- [RecognizedReflectionAccessPattern]
[Kept]
static void TestWithUnknownBindingFlags (BindingFlags bindingFlags)
{
@@ -44,7 +41,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNullType ()
{
Type type = null;
@@ -57,8 +53,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
return null;
}
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetMembers), new Type[] { typeof (BindingFlags) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetMembers" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetMembers")]
[Kept]
static void TestDataFlowType ()
{
@@ -67,7 +62,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestDataFlowWithAnnotation ([KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors |
DynamicallyAccessedMemberTypes.PublicEvents |
@@ -80,7 +74,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIfElse (bool decision)
{
Type myType;
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs
index bff3994a2..6339b7263 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/MethodUsedViaReflection.cs
@@ -7,6 +7,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupCSharpCompilerToUse ("csc")]
+ [ExpectedNoWarnings]
[SetupLinkerArgument ("--disable-opt", "unreachablebodies")]
public class MethodUsedViaReflection
{
@@ -69,9 +70,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string) },
- typeof (GetMethod_Name), nameof (GetMethod_Name.OnlyCalledViaReflection), new Type[0])]
public static void TestName ()
{
var method = typeof (GetMethod_Name).GetMethod ("OnlyCalledViaReflection");
@@ -79,7 +77,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void TestNamePrivate ()
{
// This should fail at runtime, since GetMethod(name) only works on public methods
@@ -117,9 +114,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (Type[]) },
- typeof (GetMethod_Name_Types), nameof (GetMethod_Name_Types.OnlyCalledViaReflection), new Type[0])]
public static void TestNameAndType ()
{
// Currently linker doesn't analyze the Type[] parameter and thus it marks all methods with the name and matching binding flags (public in this case)
@@ -155,9 +149,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (GetMethod_Name_BindingAttr), nameof (GetMethod_Name_BindingAttr.OnlyCalledViaReflection), new Type[0])]
public static void TestExplicitBindingFlags ()
{
var method = typeof (GetMethod_Name_BindingAttr).GetMethod ("OnlyCalledViaReflection", BindingFlags.Static | BindingFlags.Public);
@@ -193,7 +184,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void TestUnknownBindingFlags (BindingFlags bindingFlags)
{
// Since the binding flags are not known linker should mark all methods on the type
@@ -212,7 +202,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void TestUnknownBindingFlagsAndName (BindingFlags bindingFlags, string name)
{
// Since the binding flags and name are not known linker should mark all methods on the type
@@ -249,7 +238,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void TestUnknownNullBindingFlags (BindingFlags bindingFlags)
{
// The case here is a pattern which linker doesn't recognize (unlike the test case above, which passes a recognized
@@ -292,7 +280,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void TestNameBindingFlagsAndParameterModifier ()
{
var method = typeof (GetMethod_Name_BindingAttr_Binder_Types_Modifiers).GetMethod ("OnlyCalledViaReflection", BindingFlags.Public, null, new Type[] { }, null);
@@ -324,9 +311,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (BindingFlags), typeof (Binder), typeof (CallingConventions), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (GetMethod_Name_BindingAttr_Binder_CallConvention_Types_Modifiers), nameof (GetMethod_Name_BindingAttr_Binder_CallConvention_Types_Modifiers.OnlyCalledViaReflection), new Type[0])]
public static void TestNameBindingFlagsCallingConventionParameterModifier ()
{
var method = typeof (GetMethod_Name_BindingAttr_Binder_CallConvention_Types_Modifiers).GetMethod ("OnlyCalledViaReflection", BindingFlags.NonPublic, null, CallingConventions.Standard, new Type[] { }, null);
@@ -360,7 +344,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void TestNameBindingFlagsAndTypes ()
{
var method = typeof (GetMethod_Name_BindingAttr_Types).GetMethod ("OnlyCalledViaReflection", BindingFlags.Public, new Type[] { });
@@ -392,9 +375,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (int), typeof (Type[]) },
- typeof (GetMethod_Name_GenericParameterCount_Types), nameof (GetMethod_Name_GenericParameterCount_Types.OnlyCalledViaReflection), new Type[] { typeof (int), typeof (int) })]
public static void TestNameWithIntAndType ()
{
var method = typeof (GetMethod_Name_GenericParameterCount_Types).GetMethod ("OnlyCalledViaReflection", 1, new Type[] { typeof (int) });
@@ -426,9 +406,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (int), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (GetMethod_Name_GenericParameterCount_Types_Modifiers), nameof (GetMethod_Name_GenericParameterCount_Types_Modifiers.OnlyCalledViaReflection), new Type[] { typeof (int), typeof (int) })]
public static void TestNameWithIntAndTypeAndModifiers ()
{
var method = typeof (GetMethod_Name_GenericParameterCount_Types_Modifiers).GetMethod ("OnlyCalledViaReflection", 1, new Type[] { typeof (int) }, null);
@@ -460,7 +437,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void TestNameWithIntAndBindingFlags ()
{
var method = typeof (GetMethod_Name_GenericParameterCount_BindingAttr_Binder_Types_Modifiers)
@@ -494,7 +470,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void TestNameWithIntAndPrivateBindingFlags ()
{
var method = typeof (GetMethod_Name_GenericParameterCount_BindingAttr_Binder_Types_Modifiers_PrivateBinding)
@@ -526,9 +501,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (int), typeof (BindingFlags), typeof (Binder), typeof (CallingConventions), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (GetMethod_Name_GenericParameterCount_BindingAttr_Binder_CallConvention_Types_Modifiers), nameof (GetMethod_Name_GenericParameterCount_BindingAttr_Binder_CallConvention_Types_Modifiers.OnlyCalledViaReflection), new Type[0])]
public static void TestNameWithIntBindingFlagsCallingConventionParameter ()
{
var method = typeof (GetMethod_Name_GenericParameterCount_BindingAttr_Binder_CallConvention_Types_Modifiers).GetMethod ("OnlyCalledViaReflection", 1, BindingFlags.Static | BindingFlags.NonPublic, null, CallingConventions.Any, new Type[] { }, null);
@@ -538,28 +510,24 @@ namespace Mono.Linker.Tests.Cases.Reflection
#endif
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNullName ()
{
var method = typeof (MethodUsedViaReflection).GetMethod (null);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestEmptyName ()
{
var method = typeof (MethodUsedViaReflection).GetMethod (string.Empty);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNonExistingName ()
{
var method = typeof (MethodUsedViaReflection).GetMethod ("NonExisting");
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNullType ()
{
Type type = null;
@@ -573,8 +541,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (BindingFlags) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetMethod" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetMethod")]
static void TestDataFlowType ()
{
Type type = FindType ();
@@ -644,21 +611,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (BindingFlags), typeof (Binder), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (IfClass), nameof (IfClass.OnlyCalledViaReflection), new Type[0])]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (BindingFlags), typeof (Binder), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (IfClass), nameof (IfClass.ElseIfCall), new Type[0])]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (BindingFlags), typeof (Binder), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (ElseIfClass), nameof (ElseIfClass.OnlyCalledViaReflection), new Type[0])]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (BindingFlags), typeof (Binder), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (ElseIfClass), nameof (ElseIfClass.ElseIfCall), new Type[0])]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (BindingFlags), typeof (Binder), typeof (Type[]), typeof (ParameterModifier[]) },
- typeof (ElseClass), nameof (ElseClass.OnlyCalledViaReflection), new Type[0])]
public static void TestIfElse (int i)
{
Type myType;
@@ -701,9 +653,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
{ }
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string) },
- typeof (BaseClass), nameof (BaseClass.OnlyCalledViaReflection), new Type[0])]
public static void TestMethodInBaseType ()
{
var method = typeof (DerivedClass).GetMethod ("OnlyCalledViaReflection");
@@ -726,9 +675,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetMethod), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (IgnoreCaseBindingFlags), nameof (IgnoreCaseBindingFlags.OnlyCalledViaReflection), new Type[0])]
public static void TestIgnoreCaseBindingFlags ()
{
var method = typeof (IgnoreCaseBindingFlags).GetMethod ("onlycalledviareflection", BindingFlags.IgnoreCase | BindingFlags.Public);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/MethodsUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/MethodsUsedViaReflection.cs
index 5658a1a99..fcede014b 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/MethodsUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/MethodsUsedViaReflection.cs
@@ -27,21 +27,18 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestGetMethods ()
{
var methods = typeof (MethodsUsedViaReflection).GetMethods ();
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestBindingFlags ()
{
var methods = typeof (TestBindingClass).GetMethods (BindingFlags.Static | BindingFlags.Public);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestUnknownBindingFlags (BindingFlags bindingFlags)
{
// Since the binding flags are not known linker should mark all methods on the type
@@ -49,7 +46,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNullType ()
{
Type type = null;
@@ -63,8 +59,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetMethods), new Type[] { typeof (BindingFlags) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetMethods" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetMethods")]
static void TestDataFlowType ()
{
Type type = FindType ();
@@ -72,14 +67,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestDataFlowWithAnnotation ([KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))][DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type type)
{
var methods = type.GetMethods (BindingFlags.Public | BindingFlags.Static);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIfElse (int i)
{
Type myType;
@@ -94,7 +87,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIgnoreCaseBindingFlags ()
{
var methods = typeof (IgnoreCaseClass).GetMethods (BindingFlags.IgnoreCase | BindingFlags.Public);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/NestedTypeUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/NestedTypeUsedViaReflection.cs
index 2700a8793..66256ef78 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/NestedTypeUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/NestedTypeUsedViaReflection.cs
@@ -8,6 +8,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
+ [ExpectedNoWarnings]
public class NestedTypeUsedViaReflection
{
public static void Main ()
@@ -28,9 +29,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
public static class NestedType { }
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetNestedType), new Type[] { typeof (string) },
- typeof (NestedTypeUsedViaReflection.NestedType), null, (Type[]) null)]
static void TestByName ()
{
_ = typeof (NestedTypeUsedViaReflection).GetNestedType (nameof (NestedType));
@@ -55,15 +53,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
protected static class ProtectedNestedType { }
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetNestedType), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (NestedTypeUsedViaReflection.PrivateNestedType), null, (Type[]) null)]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetNestedType), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (NestedTypeUsedViaReflection.PublicNestedType), null, (Type[]) null)]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetNestedType), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (NestedTypeUsedViaReflection.ProtectedNestedType), null, (Type[]) null)]
static void TestByBindingFlags ()
{
_ = typeof (NestedTypeUsedViaReflection).GetNestedType (nameof (PrivateNestedType), BindingFlags.NonPublic);
@@ -72,9 +61,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetNestedType), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (UnknownBindingFlags.PublicNestedType), null, (Type[]) null)]
static void TestByUnknownBindingFlags (BindingFlags bindingFlags)
{
// Since the binding flags are not known linker should mark all nested types on the type
@@ -82,9 +68,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetNestedType), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (UnknownBindingFlagsAndName.PublicNestedType), null, (Type[]) null)]
static void TestByUnknownBindingFlagsAndName (BindingFlags bindingFlags, string name)
{
// Since the binding flags and name are not known linker should mark all nested types on the type
@@ -105,9 +88,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetNestedType), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (IgnoreCaseClass.IgnoreCasePublicNestedType), null, (Type[]) null)]
static void TestIgnoreCaseBindingFlags ()
{
_ = typeof (IgnoreCaseClass).GetNestedType ("ignorecasepublicnestedtype", BindingFlags.IgnoreCase | BindingFlags.Public);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/NestedTypesUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/NestedTypesUsedViaReflection.cs
index 46c490a29..4d8683aed 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/NestedTypesUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/NestedTypesUsedViaReflection.cs
@@ -9,6 +9,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
+ [ExpectedNoWarnings]
public class NestedTypesUsedViaReflection
{
public static void Main ()
@@ -27,7 +28,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
public static class NestedType { }
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestGetNestedTypes ()
{
_ = typeof (NestedTypesUsedViaReflection).GetNestedType (nameof (NestedType));
@@ -43,14 +43,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
protected static class ProtectedNestedType { }
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestByBindingFlags ()
{
_ = typeof (NestedTypesUsedViaReflection).GetNestedTypes (BindingFlags.Public);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestByUnknownBindingFlags (BindingFlags bindingFlags)
{
// Since the binding flags are not known linker should mark all nested types on the type
@@ -58,7 +56,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNullType ()
{
Type type = null;
@@ -71,8 +68,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
return null;
}
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetNestedTypes), new Type[] { typeof (BindingFlags) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetNestedTypes" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetNestedTypes")]
[Kept]
static void TestDataFlowType ()
{
@@ -81,14 +77,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestDataFlowWithAnnotation ([KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))][DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicNestedTypes)] Type type)
{
_ = type.GetNestedTypes (BindingFlags.Public | BindingFlags.Static);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIgnoreCaseBindingFlags ()
{
_ = typeof (IgnoreCaseClass).GetNestedTypes (BindingFlags.IgnoreCase | BindingFlags.Public);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/PropertiesUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/PropertiesUsedViaReflection.cs
index 4f8346b7c..2254d93b6 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/PropertiesUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/PropertiesUsedViaReflection.cs
@@ -28,21 +28,18 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestGetProperties ()
{
var properties = typeof (PropertiesUsedViaReflection).GetProperties ();
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestBindingFlags ()
{
var properties = typeof (BindingFlagsTest).GetProperties (BindingFlags.Public | BindingFlags.Static);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestUnknownBindingFlags (BindingFlags bindingFlags)
{
// Since the binding flags are not known linker should mark all properties on the type
@@ -50,14 +47,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestPropertiesOfArray ()
{
var properties = typeof (int[]).GetProperties (BindingFlags.Public);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNullType ()
{
Type type = null;
@@ -71,8 +66,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetProperties), new Type[] { typeof (BindingFlags) },
- messageCode: "IL2075", message: new string[] { "GetProperties" })]
+ [ExpectedWarning ("IL2075", "GetProperties")]
static void TestDataFlowType ()
{
Type type = FindType ();
@@ -80,14 +74,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
private static void TestDataFlowWithAnnotation ([KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))][DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicProperties)] Type type)
{
var properties = type.GetProperties (BindingFlags.Public | BindingFlags.Static);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIfElse (int i)
{
Type myType;
@@ -100,21 +92,18 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIgnoreCaseBindingFlags ()
{
var properties = typeof (IgnoreCaseBindingFlagsClass).GetProperties (BindingFlags.IgnoreCase | BindingFlags.Public);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIgnorableBindingFlags ()
{
var properties = typeof (ExactBindingBindingFlagsClass).GetProperties (BindingFlags.Public | BindingFlags.ExactBinding);
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestUnsupportedBindingFlags ()
{
var properties = typeof (ChangeTypeBindingFlagsClass).GetProperties (BindingFlags.Public | BindingFlags.SuppressChangeType);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs
index 4004e894b..bdd671987 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/PropertyUsedViaReflection.cs
@@ -6,6 +6,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupCSharpCompilerToUse ("csc")]
+ [ExpectedNoWarnings]
[SetupLinkerArgument ("--disable-opt", "unreachablebodies")]
public class PropertyUsedViaReflection
{
@@ -33,9 +34,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string) },
- typeof (PropertyUsedViaReflection), nameof (PropertyUsedViaReflection.OnlyUsedViaReflection), (Type[]) null)]
static void TestGetterAndSetter ()
{
var property = typeof (PropertyUsedViaReflection).GetProperty ("OnlyUsedViaReflection");
@@ -51,9 +49,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string) },
- typeof (PropertyUsedViaReflection), nameof (PropertyUsedViaReflection.SetterOnly), (Type[]) null)]
static void TestSetterOnly ()
{
var property = typeof (PropertyUsedViaReflection).GetProperty ("SetterOnly");
@@ -61,9 +56,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string) },
- typeof (PropertyUsedViaReflection), nameof (PropertyUsedViaReflection.GetterOnly), (Type[]) null)]
static void TestGetterOnly ()
{
var property = typeof (PropertyUsedViaReflection).GetProperty ("GetterOnly");
@@ -71,9 +63,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (BindingFlagsTest), nameof (BindingFlagsTest.PublicProperty), (Type[]) null)]
static void TestBindingFlags ()
{
var property = typeof (BindingFlagsTest).GetProperty ("PublicProperty", BindingFlags.Public);
@@ -81,9 +70,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (UnknownBindingFlags), nameof (UnknownBindingFlags.SomeProperty), (Type[]) null)]
static void TestUnknownBindingFlags (BindingFlags bindingFlags)
{
// Since the binding flags are not known linker should mark all properties on the type
@@ -92,9 +78,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (UnknownBindingFlagsAndName), nameof (UnknownBindingFlagsAndName.SomeProperty), (Type[]) null)]
static void TestUnknownBindingFlagsAndName (BindingFlags bindingFlags, string name)
{
// Since the binding flags and name are not known linker should mark all properties on the type
@@ -121,9 +104,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string) },
- typeof (Array), nameof (Array.LongLength))]
static void TestPropertyOfArray ()
{
var property = typeof (int[]).GetProperty ("LongLength");
@@ -144,8 +124,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string) },
- messageCode: "IL2075", message: new string[] { "FindType", "GetProperty" })]
+ [ExpectedWarning ("IL2075", "FindType", "GetProperty")]
static void TestDataFlowType ()
{
Type type = FindType ();
@@ -153,18 +132,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string) },
- typeof (IfClass), nameof (IfClass.SetterOnly), (Type[]) null)]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string) },
- typeof (IfClass), nameof (IfClass.GetterOnly), (Type[]) null)]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string) },
- typeof (ElseClass), nameof (ElseClass.SetterOnly), (Type[]) null)]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string) },
- typeof (ElseClass), nameof (ElseClass.GetterOnly), (Type[]) null)]
static void TestIfElse (int i)
{
Type myType;
@@ -183,18 +150,12 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string) },
- typeof (BaseClass), nameof (BaseClass.GetterSetterOnBaseClass), (Type[]) null)]
static void TestPropertyInBaseType ()
{
var property = typeof (DerivedClass).GetProperty ("GetterSetterOnBaseClass");
}
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetProperty), new Type[] { typeof (string), typeof (BindingFlags) },
- typeof (IgnoreCaseBindingFlagsClass), nameof (IgnoreCaseBindingFlagsClass.SetterOnly), (Type[]) null)]
static void TestIgnoreCaseBindingFlags ()
{
var property = typeof (IgnoreCaseBindingFlagsClass).GetProperty ("setteronly", BindingFlags.IgnoreCase | BindingFlags.Public);
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/RunClassConstructorUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/RunClassConstructorUsedViaReflection.cs
index e4670746c..0744577ec 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/RunClassConstructorUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/RunClassConstructorUsedViaReflection.cs
@@ -7,6 +7,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupCSharpCompilerToUse ("csc")]
+ [ExpectedNoWarnings]
public class RunClassConstructorUsedViaReflection
{
public static void Main ()
@@ -20,7 +21,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestRunClassConstructor ()
{
RuntimeHelpers.RunClassConstructor (typeof (OnlyUsedViaReflection).TypeHandle);
@@ -33,7 +33,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestNull ()
{
Type type = null;
@@ -47,8 +46,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (RuntimeHelpers), nameof (RuntimeHelpers.RunClassConstructor), new Type[] { typeof (RuntimeTypeHandle) },
- messageCode: "IL2059", message: new string[] { "RunClassConstructor" })]
+ [ExpectedWarning ("IL2059", nameof (RuntimeHelpers) + "." + nameof (RuntimeHelpers.RunClassConstructor))]
static void TestDataFlowType ()
{
@@ -57,10 +55,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
- [UnrecognizedReflectionAccessPattern (typeof (RuntimeHelpers), nameof (RuntimeHelpers.RunClassConstructor), new Type[] { typeof (RuntimeTypeHandle) },
- messageCode: "IL2059")]
-
+ [ExpectedWarning ("IL2059", nameof (RuntimeHelpers) + "." + nameof (RuntimeHelpers.RunClassConstructor))]
static void TestIfElseUsingRuntimeTypeHandle (int i)
{
RuntimeTypeHandle myType;
@@ -75,7 +70,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
static void TestIfElseUsingType (int i)
{
Type myType;
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/RuntimeReflectionExtensionsCalls.cs b/test/Mono.Linker.Tests.Cases/Reflection/RuntimeReflectionExtensionsCalls.cs
index 068975d4c..6d71c7ad8 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/RuntimeReflectionExtensionsCalls.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/RuntimeReflectionExtensionsCalls.cs
@@ -6,6 +6,7 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions;
namespace Mono.Linker.Tests.Cases.Reflection
{
#pragma warning disable 67 // The event {event} is not used
+ [ExpectedNoWarnings]
public class RuntimeReflectionExtensionsCalls
{
public static void Main ()
@@ -19,8 +20,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
#region GetRuntimeEvent
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (RuntimeReflectionExtensions), nameof (RuntimeReflectionExtensions.GetRuntimeEvent),
- new Type[] { typeof (Type), typeof (string) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (RuntimeReflectionExtensions) + "." + nameof (RuntimeReflectionExtensions.GetRuntimeEvent))]
public static void TestGetRuntimeEvent ()
{
typeof (ClassWithKeptMembers).GetRuntimeEvent ("PublicEvent");
@@ -28,14 +28,13 @@ namespace Mono.Linker.Tests.Cases.Reflection
typeof (ClassWithUnkeptMembers).GetRuntimeEvent ("ProtectedEvent");
GetClassWithEvent ().GetRuntimeEvent ("This string will not be reached");
typeof (Derived).GetRuntimeEvent ("Event");
- GetUnknownType ().GetRuntimeEvent (GetUnknownString ()); // UnrecognizedReflectionAccessPattern
+ GetUnknownType ().GetRuntimeEvent (GetUnknownString ()); // IL2072
}
#endregion
#region GetRuntimeField
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (RuntimeReflectionExtensions), nameof (RuntimeReflectionExtensions.GetRuntimeField),
- new Type[] { typeof (Type), typeof (string) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (RuntimeReflectionExtensions) + "." + nameof (RuntimeReflectionExtensions.GetRuntimeField))]
public static void TestGetRuntimeField ()
{
typeof (ClassWithKeptMembers).GetRuntimeField ("PublicField");
@@ -43,14 +42,13 @@ namespace Mono.Linker.Tests.Cases.Reflection
typeof (ClassWithUnkeptMembers).GetRuntimeField ("ProtectedField");
GetClassWithField ().GetRuntimeField ("This string will not be reached");
typeof (Derived).GetRuntimeField ("Field");
- GetUnknownType ().GetRuntimeField (GetUnknownString ()); // UnrecognizedReflectionAccessPattern
+ GetUnknownType ().GetRuntimeField (GetUnknownString ()); // IL2072
}
#endregion
#region GetRuntimeMethod
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (RuntimeReflectionExtensions), nameof (RuntimeReflectionExtensions.GetRuntimeMethod),
- new Type[] { typeof (Type), typeof (string), typeof (Type[]) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (RuntimeReflectionExtensions) + "." + nameof (RuntimeReflectionExtensions.GetRuntimeMethod))]
public static void TestGetRuntimeMethod ()
{
typeof (ClassWithKeptMembers).GetRuntimeMethod ("PublicMethod", Type.EmptyTypes);
@@ -58,14 +56,13 @@ namespace Mono.Linker.Tests.Cases.Reflection
typeof (ClassWithUnkeptMembers).GetRuntimeMethod ("ProtectedMethod", Type.EmptyTypes);
GetClassWithMethod ().GetRuntimeMethod ("This string will not be reached", Type.EmptyTypes);
typeof (Derived).GetRuntimeMethod ("Method", Type.EmptyTypes);
- GetUnknownType ().GetRuntimeMethod (GetUnknownString (), Type.EmptyTypes); // UnrecognizedReflectionAccessPattern
+ GetUnknownType ().GetRuntimeMethod (GetUnknownString (), Type.EmptyTypes); // IL2072
}
#endregion
#region GetRuntimeProperty
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (RuntimeReflectionExtensions), nameof (RuntimeReflectionExtensions.GetRuntimeProperty),
- new Type[] { typeof (Type), typeof (string) }, messageCode: "IL2072")]
+ [ExpectedWarning ("IL2072", nameof (RuntimeReflectionExtensions) + "." + nameof (RuntimeReflectionExtensions.GetRuntimeProperty))]
public static void TestGetRuntimeProperty ()
{
typeof (ClassWithKeptMembers).GetRuntimeProperty ("PublicProperty");
@@ -73,7 +70,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
typeof (ClassWithUnkeptMembers).GetRuntimeProperty ("ProtectedProperty");
GetClassWithProperty ().GetRuntimeProperty ("This string will not be reached");
typeof (Derived).GetRuntimeProperty ("Property");
- GetUnknownType ().GetRuntimeProperty (GetUnknownString ()); // UnrecognizedReflectionAccessPattern
+ GetUnknownType ().GetRuntimeProperty (GetUnknownString ()); // IL2072
}
#endregion
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs
index 83f53e488..e5e8147d8 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs
@@ -45,7 +45,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
[Kept]
- [RecognizedReflectionAccessPattern]
public static void TestNull ()
{
const string reflectionTypeKeptString = null;
@@ -131,9 +130,6 @@ namespace Mono.Linker.Tests.Cases.Reflection
public class AType { }
[Kept]
- [RecognizedReflectionAccessPattern (
- typeof (Type), nameof (Type.GetType), new Type[] { typeof (string), typeof (bool) },
- typeof (AType), null, (Type[]) null)]
public static void TestType ()
{
const string reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+AType";
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeDoesntExist.cs b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeDoesntExist.cs
index ef69a23e7..3f6244c10 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeDoesntExist.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflectionTypeDoesntExist.cs
@@ -5,7 +5,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupCSharpCompilerToUse ("csc")]
- [VerifyAllReflectionAccessPatternsAreValidated]
+ [ExpectedNoWarnings]
public class TypeUsedViaReflectionTypeDoesntExist
{
public static void Main ()
diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityReflectionAnalysisEnabled.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityReflectionAnalysisEnabled.cs
index 87b55c757..856c3d4a8 100644
--- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityReflectionAnalysisEnabled.cs
+++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityReflectionAnalysisEnabled.cs
@@ -8,6 +8,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.RequiresCapability
{
+ [ExpectedNoWarnings]
public class RequiresCapabilityReflectionAnalysisEnabled
{
[LogContains ("-- DynamicallyAccessedMembersEnabled --")]
@@ -24,7 +25,6 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
[Kept]
[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
[RequiresUnreferencedCode ("-- DynamicallyAccessedMembersEnabled --")]
- [RecognizedReflectionAccessPattern]
static void TestRequiresAttributeWithDynamicallyAccessedMembersEnabled ()
{
typeof (TypeWithPublicFieldsAccessed).RequiresPublicFields ();
@@ -42,7 +42,6 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
[Kept]
[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
[RequiresUnreferencedCode ("-- ReflectionPattern --")]
- [RecognizedReflectionAccessPattern]
static void TestRequiresAttributeWithReflectionPattern ()
{
typeof (TypeWithMethodAccessed).GetMethod ("PublicMethod");
@@ -60,7 +59,6 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
[Kept]
[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
[RequiresUnreferencedCode ("-- DynamicallyAccessedMembersOnGenericsEnabled --")]
- [RecognizedReflectionAccessPattern]
static void TestRequiresAttributeWithDynamicallyAccessedMembersOnGenericsEnabled ()
{
TypeRequiresPublicFields<TypeWithPublicFieldsForGenericType>.Method ();
@@ -104,13 +102,11 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[Kept]
- [ExpectedNoWarnings]
class TestRequiresAndDynamicallyAccessedMembers
{
[Kept]
[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
[RequiresUnreferencedCode ("--- RequiresAndPublicMethods ---")]
- [RecognizedReflectionAccessPattern]
static void RequiresAndPublicMethods (
[KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/LinkerCustomizations.cs b/test/Mono.Linker.Tests/TestCasesRunner/LinkerCustomizations.cs
index f1f69b963..86bc82ce3 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/LinkerCustomizations.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/LinkerCustomizations.cs
@@ -10,8 +10,6 @@ namespace Mono.Linker.Tests.TestCasesRunner
{
public TestDependencyRecorder DependencyRecorder { get; set; }
- public TestReflectionPatternRecorder ReflectionPatternRecorder { get; set; }
-
public event Action<LinkContext> CustomizeContext;
public void CustomizeLinkContext (LinkContext context)
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
index 8f18a2b7e..095302ddf 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
@@ -190,7 +190,7 @@ namespace Mono.Linker.Tests.TestCasesRunner
protected virtual void AdditionalChecking (LinkedTestCaseResult linkResult, AssemblyDefinition original)
{
bool checkRemainingErrors = !HasAttribute (original.MainModule.GetType (linkResult.TestCase.ReconstructedFullTypeName), nameof (SkipRemainingErrorsValidationAttribute));
- VerifyLoggedMessages (original, linkResult.Logger, linkResult.Customizations.ReflectionPatternRecorder, checkRemainingErrors);
+ VerifyLoggedMessages (original, linkResult.Logger, checkRemainingErrors);
VerifyRecordedDependencies (original, linkResult.Customizations.DependencyRecorder);
}
@@ -670,12 +670,11 @@ namespace Mono.Linker.Tests.TestCasesRunner
yield return assembly;
}
- void VerifyLoggedMessages (AssemblyDefinition original, LinkerTestLogger logger, TestReflectionPatternRecorder reflectionPatternRecorder, bool checkRemainingErrors)
+ void VerifyLoggedMessages (AssemblyDefinition original, LinkerTestLogger logger, bool checkRemainingErrors)
{
List<MessageContainer> loggedMessages = logger.GetLoggedMessages ();
List<(IMemberDefinition, CustomAttribute)> expectedNoWarningsAttributes = new List<(IMemberDefinition, CustomAttribute)> ();
foreach (var attrProvider in GetAttributeProviders (original)) {
- bool foundReflectionAccessPatternAttributesToVerify = false;
foreach (var attr in attrProvider.CustomAttributes) {
if (!IsProducedByLinker (attr))
continue;
@@ -812,160 +811,6 @@ namespace Mono.Linker.Tests.TestCasesRunner
}
break;
- case nameof (RecognizedReflectionAccessPatternAttribute): {
- foundReflectionAccessPatternAttributesToVerify = true;
-
- // Special case for default .ctor - just trigger the overall verification on the method
- // but don't verify any specific pattern.
- if (attr.ConstructorArguments.Count == 0)
- continue;
-
- string expectedSourceMember = GetFullMemberNameFromDefinition (attrProvider);
- string expectedReflectionMember = GetFullMemberNameFromReflectionAccessPatternAttribute (attr, constructorArgumentsOffset: 0, out string expectedReflectionMemberGenericMember);
- string expectedAccessedItem = GetFullMemberNameFromReflectionAccessPatternAttribute (attr, constructorArgumentsOffset: 3, out string _genericMember);
-
- var matchedPatterns = reflectionPatternRecorder.RecognizedPatterns.Where (pattern => {
- if (GetFullMemberNameFromDefinition (pattern.Source) != expectedSourceMember)
- return false;
-
- string actualAccessOperation = null;
- if (pattern.SourceInstruction?.Operand is IMetadataTokenProvider sourceOperand)
- actualAccessOperation = GetFullMemberNameFromDefinition (sourceOperand);
-
- if (actualAccessOperation != expectedReflectionMember)
- return false;
-
- if (GetFullMemberNameFromDefinition (pattern.AccessedItem) != expectedAccessedItem)
- return false;
-
- return true;
- });
-
- if (!matchedPatterns.Any ()) {
- string sourceMemberCandidates = string.Join (Environment.NewLine, reflectionPatternRecorder.RecognizedPatterns
- .Where (p => GetFullMemberNameFromDefinition (p.Source)?.ToLowerInvariant ()?.Contains (expectedReflectionMember.ToLowerInvariant ()) == true)
- .Select (p => "\t" + RecognizedReflectionAccessPatternToString (p)));
- string reflectionMemberCandidates = string.Join (Environment.NewLine, reflectionPatternRecorder.RecognizedPatterns
- .Where (p => GetFullMemberNameFromDefinition (p.SourceInstruction?.Operand as IMetadataTokenProvider)?.ToLowerInvariant ()?.Contains (expectedReflectionMember.ToLowerInvariant ()) == true)
- .Select (p => "\t" + RecognizedReflectionAccessPatternToString (p)));
-
- Assert.Fail (
- $"Expected to find recognized reflection access pattern '{expectedSourceMember}: Usage of {expectedReflectionMember} accessed {expectedAccessedItem}'{Environment.NewLine}" +
- $"Potential patterns matching the source member: {Environment.NewLine}{sourceMemberCandidates}{Environment.NewLine}" +
- $"Potential patterns matching the reflection member: {Environment.NewLine}{reflectionMemberCandidates}{Environment.NewLine}" +
- $"If there's no matches, try to specify just a part of the source member or reflection member name and rerun the test to get potential matches.");
- }
-
- reflectionPatternRecorder.RecognizedPatterns.Remove (matchedPatterns.First ());
- }
- break;
-
- case nameof (UnrecognizedReflectionAccessPatternAttribute): {
- Debug.Assert (attr.ConstructorArguments[0].Type.MetadataType != MetadataType.String);
-
- foundReflectionAccessPatternAttributesToVerify = true;
-
- string expectedSourceMember = GetFullMemberNameFromDefinition (attrProvider);
- string expectedReflectionMember = GetFullMemberNameFromReflectionAccessPatternAttribute (attr, constructorArgumentsOffset: 0, out string expectedReflectionMemberGenericMember);
- string expectedReflectionMemberWithoutReturnType = GetFullMemberNameFromReflectionAccessPatternAttribute (attr, constructorArgumentsOffset: 0, out string _genericType, includeReturnType: false);
- string[] expectedMessageParts = GetMessagePartsFromReflectionAccessPatternAttribute (attr, 3);
- int? expectedMessageCode = null;
- if (attr.ConstructorArguments.Count >= 5) {
- var codeString = (string) attr.ConstructorArguments[4].Value;
- if (codeString != null) {
- if (!codeString.StartsWith ("IL"))
- Assert.Fail ($"The warning code specified in {nameof (UnrecognizedReflectionAccessPatternAttribute)} must start with the 'IL' prefix. Specified value: '{codeString}'");
- expectedMessageCode = int.Parse (codeString.Substring (2));
- }
- }
-
- // Validate expected unrecognized patterns by looking for them in both the logged messages and the recorded unrecognized patterns.
- // Checking for both here ensures that the unrecognized pattern attributes use the same signature formats as the logged warnings.
- // The Roslyn analyzer will treat these attributes similarly, checking them against logged diagnostics only.
- // Eventually this should go away as we replace UnrecognizedReflectionAccessPatternAttribute with ExpectedWarningAttribute.
-
- var matchedMessages = loggedMessages.Where (mc => {
- if (mc.Category != MessageCategory.Warning)
- return false;
-
- if (!LogMessageHasSameOriginMember (mc, attrProvider))
- return false;
-
- if (!mc.Text.Contains (expectedReflectionMemberWithoutReturnType))
- return false;
-
- if (expectedReflectionMemberGenericMember != null && !mc.Text.Contains (expectedReflectionMemberGenericMember))
- return false;
-
- // Note: string.Compare(string, StringComparison) doesn't exist in .NET Framework API set
- if (expectedMessageParts != null && expectedMessageParts.Any (p => mc.Text.IndexOf (p, StringComparison.Ordinal) < 0))
- return false;
-
- if (expectedMessageCode.HasValue && mc.Code != expectedMessageCode.Value)
- return false;
-
- return true;
- }).ToList ();
-
- var matchedPatterns = reflectionPatternRecorder.UnrecognizedPatterns.Where (pattern => {
- if (GetFullMemberNameFromDefinition (pattern.Source) != expectedSourceMember)
- return false;
-
- string actualAccessOperation = null;
- string actualAccessGenericMember = null;
- if (pattern.SourceInstruction?.Operand is IMetadataTokenProvider sourceOperand)
- actualAccessOperation = GetFullMemberNameFromDefinition (sourceOperand);
- else
- actualAccessOperation = GetFullMemberNameFromDefinition (pattern.AccessedItem, out actualAccessGenericMember);
-
- if (actualAccessOperation != expectedReflectionMember)
- return false;
-
- if (actualAccessGenericMember != expectedReflectionMemberGenericMember)
- return false;
-
- if (expectedMessageParts != null && expectedMessageParts.Any (p => pattern.Message.IndexOf (p, StringComparison.Ordinal) < 0))
- return false;
-
- if (expectedMessageCode.HasValue && pattern.MessageCode != expectedMessageCode.Value)
- return false;
-
- return true;
- }).ToList ();
-
- if (matchedMessages.Any ())
- loggedMessages.Remove (matchedMessages.First ());
-
- if (matchedPatterns.Any ())
- reflectionPatternRecorder.UnrecognizedPatterns.Remove (matchedPatterns.First ());
-
- string expectedUnrecognizedPatternMessage =
- $"Expected to find unrecognized reflection access pattern '{(expectedMessageCode == null ? "" : ("IL" + expectedMessageCode + " "))}" +
- $"{expectedSourceMember}: Usage of {expectedReflectionMember} unrecognized " +
- $"{(expectedMessageParts == null ? string.Empty : "and message contains " + string.Join (" ", expectedMessageParts.Select (p => "'" + p + "'")))}";
-
- Assert.AreEqual (matchedMessages.Count, matchedPatterns.Count,
- $"Inconsistency between logged messages and recorded patterns.{Environment.NewLine}{expectedUnrecognizedPatternMessage}{Environment.NewLine}" +
- $"Matched messages: {Environment.NewLine}{string.Join (Environment.NewLine, matchedMessages.Select (mc => "\t" + mc.Text))}{Environment.NewLine}" +
- $"Matched unrecognized patterns: {Environment.NewLine}{string.Join (Environment.NewLine, matchedPatterns.Select (p => "\t" + RecognizedReflectionAccessPatternToString (p)))}{Environment.NewLine}");
-
- if (!matchedMessages.Any ()) {
- string sourceMemberCandidates = string.Join (Environment.NewLine, loggedMessages
- .Where (mc => mc.Text.Contains (expectedSourceMember.ToLowerInvariant ()))
- .Select (mc => "\t" + mc.Text));
- string reflectionMemberCandidates = string.Join (Environment.NewLine, loggedMessages
- .Where (mc => mc.Text.Contains (expectedReflectionMember.ToLowerInvariant ()))
- .Select (mc => "\t" + mc.Text));
-
- Assert.Fail (
- $"{expectedUnrecognizedPatternMessage}{Environment.NewLine}" +
- $"Potential messages matching the source member: {Environment.NewLine}{sourceMemberCandidates}{Environment.NewLine}" +
- $"Potential messages matching the reflection member: {Environment.NewLine}{reflectionMemberCandidates}{Environment.NewLine}" +
- $"If there's no matches, try to specify just a part of the source member or reflection member name and rerun the test to get potential matches.");
- }
- }
- break;
-
case nameof (ExpectedNoWarningsAttribute):
// Postpone processing of negative checks, to make it possible to mark some warnings as expected (will be removed from the list above)
// and then do the negative check on the rest.
@@ -975,52 +820,6 @@ namespace Mono.Linker.Tests.TestCasesRunner
break;
}
}
-
- // Validate that there are no other reported unrecognized patterns on the member
- if (foundReflectionAccessPatternAttributesToVerify) {
- string expectedSourceMember = GetFullMemberNameFromDefinition (attrProvider);
- var unrecognizedPatternsForSourceMember = reflectionPatternRecorder.UnrecognizedPatterns.Where (pattern => {
- if (GetFullMemberNameFromDefinition (pattern.Source) != expectedSourceMember)
- return false;
-
- return true;
- });
-
- if (unrecognizedPatternsForSourceMember.Any ()) {
- string unrecognizedPatterns = string.Join (Environment.NewLine, unrecognizedPatternsForSourceMember
- .Select (p => "\t" + UnrecognizedReflectionAccessPatternToString (p)));
-
- Assert.Fail (
- $"Member {expectedSourceMember} has either {nameof (RecognizedReflectionAccessPatternAttribute)} or {nameof (UnrecognizedReflectionAccessPatternAttribute)} attributes.{Environment.NewLine}" +
- $"Some reported unrecognized patterns are not expected by the test (there's no matching attribute for them):{Environment.NewLine}" +
- $"{unrecognizedPatterns}");
- }
- }
- }
-
- foreach (var typeToVerify in original.MainModule.AllDefinedTypes ()) {
- foreach (var attr in typeToVerify.CustomAttributes) {
- if (attr.AttributeType.Resolve ()?.Name == nameof (VerifyAllReflectionAccessPatternsAreValidatedAttribute)) {
- // By now all verified recorded patterns were removed from the test recorder lists, so validate
- // that there are no remaining patterns for this type.
- var recognizedPatternsForType = reflectionPatternRecorder.RecognizedPatterns
- .Where (pattern => (pattern.Source is IMemberDefinition member) && member.DeclaringType?.FullName == typeToVerify.FullName);
- var unrecognizedPatternsForType = reflectionPatternRecorder.UnrecognizedPatterns
- .Where (pattern => (pattern.Source is IMemberDefinition member) && member.DeclaringType?.FullName == typeToVerify.FullName);
-
- if (recognizedPatternsForType.Any () || unrecognizedPatternsForType.Any ()) {
- string recognizedPatterns = string.Join (Environment.NewLine, recognizedPatternsForType
- .Select (p => "\t" + RecognizedReflectionAccessPatternToString (p)));
- string unrecognizedPatterns = string.Join (Environment.NewLine, unrecognizedPatternsForType
- .Select (p => "\t" + UnrecognizedReflectionAccessPatternToString (p)));
-
- Assert.Fail (
- $"All reflection patterns should be verified by test attributes for type {typeToVerify.FullName}, but some were not: {Environment.NewLine}" +
- $"Recognized patterns which were not verified: {Environment.NewLine}{recognizedPatterns}{Environment.NewLine}" +
- $"Unrecognized patterns which were not verified: {Environment.NewLine}{unrecognizedPatterns}{Environment.NewLine}");
- }
- }
- }
}
foreach ((var attrProvider, var attr) in expectedNoWarningsAttributes) {
@@ -1120,13 +919,6 @@ namespace Mono.Linker.Tests.TestCasesRunner
}
}
- static void RemoveFromList<T> (List<T> list, IEnumerable<T> itemsToRemove)
- {
- foreach (var item in itemsToRemove.ToList ()) {
- list.Remove (item);
- }
- }
-
void VerifyExpectedInstructionSequenceOnMemberInAssembly (CustomAttribute inAssemblyAttribute, TypeDefinition linkedType)
{
var originalType = GetOriginalTypeFromInAssemblyAttribute (inAssemblyAttribute);
@@ -1149,77 +941,6 @@ namespace Mono.Linker.Tests.TestCasesRunner
Assert.Fail ($"Invalid test assertion. No method named `{memberName}` exists on the original type `{originalType}`");
}
- static string GetFullMemberNameFromReflectionAccessPatternAttribute (CustomAttribute attr, int constructorArgumentsOffset, out string genericMember, bool includeReturnType = true)
- {
- genericMember = null;
- var type = (attr.ConstructorArguments[constructorArgumentsOffset].Value as TypeReference).Resolve ();
- Debug.Assert (type != null);
- var memberName = (string) attr.ConstructorArguments[constructorArgumentsOffset + 1].Value;
- var parameterTypes = (CustomAttributeArgument[]) attr.ConstructorArguments[constructorArgumentsOffset + 2].Value;
-
- string genericParameter = null;
-
- static string GetFullName (TypeDefinition type, string memberName, CustomAttributeArgument[] parameterTypes)
- {
- string fullName = type.GetDisplayName ();
-
- if (memberName == null)
- return fullName;
-
- fullName += "." + memberName;
- if (memberName.EndsWith (".get") || memberName.EndsWith (".set"))
- return fullName;
-
- if (parameterTypes != null) {
- fullName += "(";
- fullName += string.Join (", ", parameterTypes.Select (pt => pt.Value switch {
- TypeReference typeRef => typeRef.GetDisplayNameWithoutNamespace ().ToString (),
- string str => str,
- _ => throw new NotImplementedException ()
- }));
- fullName += ")";
- }
-
- return fullName;
- }
-
- var fullName = GetFullName (type, memberName, parameterTypes);
-
- if (attr.AttributeType.Name == "UnrecognizedReflectionAccessPatternAttribute") {
- if (includeReturnType) {
- var returnType = attr.ConstructorArguments[constructorArgumentsOffset + 5].Value;
- if (returnType != null)
- fullName = fullName.Insert (0, returnType.ToString () + " ");
- }
-
- genericParameter = attr.ConstructorArguments[constructorArgumentsOffset + 6].Value as string;
- }
-
- if (genericParameter != null) {
- Debug.Assert (memberName == null || parameterTypes != null,
- "Generic parameter should only be specified for types (with null memberName), or methods (with non-null parameterTypes).");
-
- genericMember = fullName;
- return genericParameter;
- }
-
- return fullName;
- }
-
- static string[] GetMessagePartsFromReflectionAccessPatternAttribute (CustomAttribute attr, int messageParameterIndex)
- {
- var messageParameter = attr.ConstructorArguments[messageParameterIndex].Value;
- if (messageParameter is CustomAttributeArgument messageAttributeArgument)
- messageParameter = messageAttributeArgument.Value;
-
- if (messageParameter is null)
- return null;
- else if (messageParameter is string messagePartString)
- return new string[] { messagePartString };
- else
- return ((CustomAttributeArgument[]) messageParameter).Select (p => (string) p.Value).ToArray ();
- }
-
static string GetFullMemberNameFromDefinition (IMetadataTokenProvider member)
{
return GetFullMemberNameFromDefinition (member, out string genericMember);
@@ -1271,26 +992,6 @@ namespace Mono.Linker.Tests.TestCasesRunner
throw new NotImplementedException ($"Getting the full member name has not been implemented for {member}");
}
- static string RecognizedReflectionAccessPatternToString (TestReflectionPatternRecorder.ReflectionAccessPattern pattern)
- {
- string operationDescription;
- if (pattern.SourceInstruction?.Operand is IMetadataTokenProvider instructionOperand) {
- operationDescription = "Usage of " + GetFullMemberNameFromDefinition (instructionOperand) + " accessed";
- } else
- operationDescription = "Accessed";
- return $"{GetFullMemberNameFromDefinition (pattern.Source)}: {operationDescription} {GetFullMemberNameFromDefinition (pattern.AccessedItem)}";
- }
-
- static string UnrecognizedReflectionAccessPatternToString (TestReflectionPatternRecorder.ReflectionAccessPattern pattern)
- {
- string operationDescription;
- if (pattern.SourceInstruction?.Operand is IMetadataTokenProvider instructionOperand) {
- operationDescription = "Usage of " + GetFullMemberNameFromDefinition (instructionOperand) + " unrecognized";
- } else
- operationDescription = "Usage of " + GetFullMemberNameFromDefinition (pattern.AccessedItem) + " unrecognized";
- return $"IL{pattern.MessageCode} {GetFullMemberNameFromDefinition (pattern.Source)}: {operationDescription} '{pattern.Message}'";
- }
-
protected TypeDefinition GetOriginalTypeFromInAssemblyAttribute (CustomAttribute inAssemblyAttribute)
{
string assemblyName;
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadataProvider.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadataProvider.cs
index fdcde52f7..888df76b3 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadataProvider.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadataProvider.cs
@@ -95,15 +95,6 @@ namespace Mono.Linker.Tests.TestCasesRunner
};
}
- if (ValidatesReflectionAccessPatterns (_testCaseTypeDefinition)) {
- customizations.ReflectionPatternRecorder = new TestReflectionPatternRecorder ();
- customizations.CustomizeContext += context => {
- customizations.ReflectionPatternRecorder.PreviousRecorder = context.ReflectionPatternRecorder;
- context.ReflectionPatternRecorder = customizations.ReflectionPatternRecorder;
- context.LogMessages = true;
- };
- }
-
if (ValidatesLogMessages (_testCaseTypeDefinition)) {
customizations.CustomizeContext += context => {
context.LogMessages = true;
@@ -111,26 +102,6 @@ namespace Mono.Linker.Tests.TestCasesRunner
}
}
- bool ValidatesReflectionAccessPatterns (TypeDefinition testCaseTypeDefinition)
- {
- if (testCaseTypeDefinition.HasNestedTypes) {
- var nestedTypes = new Queue<TypeDefinition> (testCaseTypeDefinition.NestedTypes.ToList ());
- while (nestedTypes.Count > 0) {
- if (ValidatesReflectionAccessPatterns (nestedTypes.Dequeue ()))
- return true;
- }
- }
-
- if (testCaseTypeDefinition.CustomAttributes.Any (attr =>
- attr.AttributeType.Name == nameof (VerifyAllReflectionAccessPatternsAreValidatedAttribute))
- || testCaseTypeDefinition.AllMembers ().Concat (testCaseTypeDefinition.AllDefinedTypes ()).Any (m => m.CustomAttributes.Any (attr =>
- attr.AttributeType.Name == nameof (RecognizedReflectionAccessPatternAttribute) ||
- attr.AttributeType.Name == nameof (UnrecognizedReflectionAccessPatternAttribute))))
- return true;
-
- return false;
- }
-
bool ValidatesLogMessages (TypeDefinition testCaseTypeDefinition)
{
if (testCaseTypeDefinition.HasNestedTypes) {
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestReflectionPatternRecorder.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestReflectionPatternRecorder.cs
deleted file mode 100644
index 7143952ed..000000000
--- a/test/Mono.Linker.Tests/TestCasesRunner/TestReflectionPatternRecorder.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-using System.Collections.Generic;
-using Mono.Cecil;
-using Mono.Cecil.Cil;
-
-namespace Mono.Linker.Tests.TestCasesRunner
-{
- public class TestReflectionPatternRecorder : IReflectionPatternRecorder
- {
- public IReflectionPatternRecorder PreviousRecorder;
-
- public struct ReflectionAccessPattern
- {
- public ICustomAttributeProvider Source;
- public Instruction SourceInstruction;
- public IMetadataTokenProvider AccessedItem;
- public string Message;
- public int MessageCode;
- }
-
- public List<ReflectionAccessPattern> RecognizedPatterns = new List<ReflectionAccessPattern> ();
- public List<ReflectionAccessPattern> UnrecognizedPatterns = new List<ReflectionAccessPattern> ();
-
- public void RecognizedReflectionAccessPattern (ICustomAttributeProvider source, Instruction sourceInstruction, IMetadataTokenProvider accessedItem)
- {
- PreviousRecorder?.RecognizedReflectionAccessPattern (source, sourceInstruction, accessedItem);
- RecognizedPatterns.Add (new ReflectionAccessPattern {
- Source = source,
- SourceInstruction = sourceInstruction,
- AccessedItem = accessedItem
- });
- }
-
- public void UnrecognizedReflectionAccessPattern (in MessageOrigin origin, ICustomAttributeProvider source, Instruction sourceInstruction, IMetadataTokenProvider accessedItem, string message, int messageCode)
- {
- PreviousRecorder?.UnrecognizedReflectionAccessPattern (origin, source, sourceInstruction, accessedItem, message, messageCode);
- UnrecognizedPatterns.Add (new ReflectionAccessPattern {
- Source = source,
- SourceInstruction = sourceInstruction,
- AccessedItem = accessedItem,
- Message = message,
- MessageCode = messageCode
- });
- }
- }
-}