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:
authorMateo Torres-Ruiz <mateoatr@users.noreply.github.com>2021-09-17 00:42:34 +0300
committerGitHub <noreply@github.com>2021-09-17 00:42:34 +0300
commit6f237bb253a4e86479b0bf6949ec68e5793505f1 (patch)
tree2e778bc0f1da8ad850bc48ed71c397b43377dd2e
parent7c88b9ba691d65014934637acfec27f1a985cea9 (diff)
Warn on RUC annotated attribute ctors (analyzer) (#2201)
* Warn on usage of attributes with annotated ctors * PR feedback Add ProducedBy from Test Restructure Add support for SetupCompileBefore in the analyzer Run analyzer tests on all members (not only methods) Move tests to RequiresCapability * Enable analyzer tests for attributes which use RUC annotated properties * Lint * Rename CheckAttributeCtor Check for instantiations that set annotated properties * Apply suggestions from code review Co-authored-by: Andy Gocke <angocke@microsoft.com> * Update comment Rename Linker => Trimmer in ProducedBy * Fix applied suggestions * Lint Co-authored-by: Andy Gocke <angocke@microsoft.com>
-rw-r--r--src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs104
-rw-r--r--test/ILLink.RoslynAnalyzer.Tests/LinkerTestCases.cs14
-rw-r--r--test/ILLink.RoslynAnalyzer.Tests/TestCaseUtils.cs26
-rw-r--r--test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs6
-rw-r--r--test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpAnalyzerVerifier`1.cs14
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedWarningAttribute.cs7
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Assertions/ProducedBy.cs16
-rw-r--r--test/Mono.Linker.Tests.Cases/RequiresCapability/Dependencies/RequiresUnreferencedCodeOnAttributeCtorAttribute.cs17
-rw-r--r--test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeCapability.cs201
-rw-r--r--test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeInCompilerGeneratedCode.cs36
-rw-r--r--test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeOnAttributeCtor.cs91
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs8
12 files changed, 381 insertions, 159 deletions
diff --git a/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs b/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs
index 2ed43d286..dd046417f 100644
--- a/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs
+++ b/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs
@@ -43,26 +43,44 @@ namespace ILLink.RoslynAnalyzer
context.RegisterSymbolAction (symbolAnalysisContext => {
var methodSymbol = (IMethodSymbol) symbolAnalysisContext.Symbol;
CheckMatchingAttributesInOverrides (symbolAnalysisContext, methodSymbol);
+ CheckAttributeInstantiation (symbolAnalysisContext, methodSymbol);
+ foreach (var typeParameter in methodSymbol.TypeParameters)
+ CheckAttributeInstantiation (symbolAnalysisContext, typeParameter);
+
}, SymbolKind.Method);
context.RegisterSymbolAction (symbolAnalysisContext => {
var typeSymbol = (INamedTypeSymbol) symbolAnalysisContext.Symbol;
CheckMatchingAttributesInInterfaces (symbolAnalysisContext, typeSymbol);
+ CheckAttributeInstantiation (symbolAnalysisContext, typeSymbol);
+ foreach (var typeParameter in typeSymbol.TypeParameters)
+ CheckAttributeInstantiation (symbolAnalysisContext, typeParameter);
+
}, SymbolKind.NamedType);
- if (AnalyzerDiagnosticTargets.HasFlag (DiagnosticTargets.Property)) {
- context.RegisterSymbolAction (symbolAnalysisContext => {
- var propertySymbol = (IPropertySymbol) symbolAnalysisContext.Symbol;
+
+ context.RegisterSymbolAction (symbolAnalysisContext => {
+ var propertySymbol = (IPropertySymbol) symbolAnalysisContext.Symbol;
+ if (AnalyzerDiagnosticTargets.HasFlag (DiagnosticTargets.Property)) {
CheckMatchingAttributesInOverrides (symbolAnalysisContext, propertySymbol);
- }, SymbolKind.Property);
- }
+ }
+
+ CheckAttributeInstantiation (symbolAnalysisContext, propertySymbol);
+ }, SymbolKind.Property);
- if (AnalyzerDiagnosticTargets.HasFlag (DiagnosticTargets.Event)) {
- context.RegisterSymbolAction (symbolAnalysisContext => {
- var eventSymbol = (IEventSymbol) symbolAnalysisContext.Symbol;
+ context.RegisterSymbolAction (symbolAnalysisContext => {
+ var eventSymbol = (IEventSymbol) symbolAnalysisContext.Symbol;
+ if (AnalyzerDiagnosticTargets.HasFlag (DiagnosticTargets.Event)) {
CheckMatchingAttributesInOverrides (symbolAnalysisContext, eventSymbol);
- }, SymbolKind.Event);
- }
+ }
+
+ CheckAttributeInstantiation (symbolAnalysisContext, eventSymbol);
+ }, SymbolKind.Event);
+
+ context.RegisterSymbolAction (symbolAnalysisContext => {
+ var fieldSymbol = (IFieldSymbol) symbolAnalysisContext.Symbol;
+ CheckAttributeInstantiation (symbolAnalysisContext, fieldSymbol);
+ }, SymbolKind.Field);
context.RegisterOperationAction (operationContext => {
var methodInvocation = (IInvocationOperation) operationContext.Operation;
@@ -99,12 +117,17 @@ namespace ILLink.RoslynAnalyzer
CheckCalledMember (operationContext, prop, incompatibleMembers);
}, OperationKind.PropertyReference);
- if (AnalyzerDiagnosticTargets.HasFlag (DiagnosticTargets.Event)) {
- context.RegisterOperationAction (operationContext => {
- var eventRef = (IEventReferenceOperation) operationContext.Operation;
- CheckCalledMember (operationContext, eventRef.Member, incompatibleMembers);
- }, OperationKind.EventReference);
- }
+ context.RegisterOperationAction (operationContext => {
+ var eventRef = (IEventReferenceOperation) operationContext.Operation;
+ var eventSymbol = (IEventSymbol) eventRef.Member;
+ CheckCalledMember (operationContext, eventSymbol, incompatibleMembers);
+
+ if (eventSymbol.AddMethod is IMethodSymbol eventAddMethod)
+ CheckCalledMember (operationContext, eventAddMethod, incompatibleMembers);
+
+ if (eventSymbol.RemoveMethod is IMethodSymbol eventRemoveMethod)
+ CheckCalledMember (operationContext, eventRemoveMethod, incompatibleMembers);
+ }, OperationKind.EventReference);
context.RegisterOperationAction (operationContext => {
var delegateCreation = (IDelegateCreationOperation) operationContext.Operation;
@@ -115,6 +138,7 @@ namespace ILLink.RoslynAnalyzer
methodSymbol = lambda.Symbol;
else
return;
+
CheckCalledMember (operationContext, methodSymbol, incompatibleMembers);
}, OperationKind.DelegateCreation);
@@ -125,6 +149,35 @@ namespace ILLink.RoslynAnalyzer
foreach (var extraSyntaxNodeAction in ExtraSyntaxNodeActions)
context.RegisterSyntaxNodeAction (extraSyntaxNodeAction.Action, extraSyntaxNodeAction.SyntaxKind);
+ void CheckAttributeInstantiation (
+ SymbolAnalysisContext symbolAnalysisContext,
+ ISymbol symbol)
+ {
+ if (symbol.HasAttribute (RequiresAttributeName))
+ return;
+
+ foreach (var attr in symbol.GetAttributes ()) {
+ if (TryGetRequiresAttribute (attr.AttributeConstructor, out var requiresAttribute)) {
+ symbolAnalysisContext.ReportDiagnostic (Diagnostic.Create (RequiresDiagnosticRule,
+ symbol.Locations[0], attr.AttributeConstructor!.Name, GetMessageFromAttribute (requiresAttribute), GetUrlFromAttribute (requiresAttribute)));
+ }
+
+ foreach (var namedArgument in attr.NamedArguments) {
+ var propertyOnArgument = attr.AttributeClass!.GetMembers ()
+ .Where (m => m.Kind == SymbolKind.Property && m.Name == namedArgument.Key)
+ .FirstOrDefault ();
+
+ if (propertyOnArgument is not IPropertySymbol setProperty)
+ continue;
+
+ if (setProperty.SetMethod is IMethodSymbol setter && setter.TryGetAttribute (RequiresAttributeFullyQualifiedName, out var requiresAttributeOnProperty)) {
+ symbolAnalysisContext.ReportDiagnostic (Diagnostic.Create (RequiresDiagnosticRule,
+ symbol.Locations[0], attr.AttributeConstructor!.Name, GetMessageFromAttribute (requiresAttributeOnProperty), GetUrlFromAttribute (requiresAttributeOnProperty)));
+ }
+ }
+ }
+ }
+
void CheckStaticConstructors (OperationAnalysisContext operationContext,
ImmutableArray<IMethodSymbol> staticConstructors)
{
@@ -144,10 +197,11 @@ namespace ILLink.RoslynAnalyzer
// Do not emit any diagnostic if caller is annotated with the attribute too.
if (containingSymbol.HasAttribute (RequiresAttributeName))
return;
+
// Check also for RequiresAttribute in the associated symbol
- if (containingSymbol is IMethodSymbol methodSymbol && methodSymbol.AssociatedSymbol is not null && methodSymbol.AssociatedSymbol!.HasAttribute (RequiresAttributeName)) {
+ if (containingSymbol is IMethodSymbol methodSymbol && methodSymbol.AssociatedSymbol is not null && methodSymbol.AssociatedSymbol!.HasAttribute (RequiresAttributeName))
return;
- }
+
// If calling an instance constructor, check first for any static constructor since it will be called implicitly
if (member.ContainingType is { } containingType && operationContext.Operation is IObjectCreationOperation)
CheckStaticConstructors (operationContext, containingType.StaticConstructors);
@@ -163,6 +217,14 @@ namespace ILLink.RoslynAnalyzer
member = method.OverriddenMethod;
if (TryGetRequiresAttribute (member, out var requiresAttribute)) {
+ if (member is IMethodSymbol eventAccessorMethod && eventAccessorMethod.AssociatedSymbol is IEventSymbol eventSymbol) {
+ // If the annotated member is an event accessor, we warn on the event to match the linker behavior.
+ member = eventAccessorMethod.ContainingSymbol;
+ operationContext.ReportDiagnostic (Diagnostic.Create (RequiresDiagnosticRule,
+ eventSymbol.Locations[0], member.Name, GetMessageFromAttribute (requiresAttribute), GetUrlFromAttribute (requiresAttribute)));
+ return;
+ }
+
ReportRequiresDiagnostic (operationContext, member, requiresAttribute);
}
}
@@ -281,9 +343,12 @@ namespace ILLink.RoslynAnalyzer
/// <param name="member">Symbol of the member to search attribute.</param>
/// <param name="requiresAttribute">Output variable in case of matching Requires attribute.</param>
/// <returns>True if the member contains a Requires attribute; otherwise, returns false.</returns>
- private bool TryGetRequiresAttribute (ISymbol member, [NotNullWhen (returnValue: true)] out AttributeData? requiresAttribute)
+ private bool TryGetRequiresAttribute (ISymbol? member, [NotNullWhen (returnValue: true)] out AttributeData? requiresAttribute)
{
requiresAttribute = null;
+ if (member == null)
+ return false;
+
foreach (var _attribute in member.GetAttributes ()) {
if (_attribute.AttributeClass is { } attrClass &&
attrClass.HasName (RequiresAttributeFullyQualifiedName) &&
@@ -292,6 +357,7 @@ namespace ILLink.RoslynAnalyzer
return true;
}
}
+
return false;
}
diff --git a/test/ILLink.RoslynAnalyzer.Tests/LinkerTestCases.cs b/test/ILLink.RoslynAnalyzer.Tests/LinkerTestCases.cs
index bfd70ca6e..9d0feb1b3 100644
--- a/test/ILLink.RoslynAnalyzer.Tests/LinkerTestCases.cs
+++ b/test/ILLink.RoslynAnalyzer.Tests/LinkerTestCases.cs
@@ -15,14 +15,14 @@ namespace ILLink.RoslynAnalyzer.Tests
{
[Theory]
[MemberData (nameof (TestCaseUtils.GetTestData), parameters: nameof (RequiresCapability))]
- public void RequiresCapability (MethodDeclarationSyntax m, List<AttributeSyntax> attrs)
+ public void RequiresCapability (MemberDeclarationSyntax m, List<AttributeSyntax> attrs)
{
- switch (m.Identifier.ValueText) {
- // There is a discrepancy between the way linker and the analyzer represent the location of the error,
- // linker will point to the method caller and the analyzer will point to a line of code.
- // The TestTypeIsBeforeFieldInit scenario is supported by the analyzer, just the diagnostic message is different
- // We verify the analyzer generating the right diagnostic in RequiresUnreferencedCodeAnalyzerTests.cs
- case "TestTypeIsBeforeFieldInit":
+ if (m is MethodDeclarationSyntax method &&
+ method.Identifier.ValueText == "TestTypeIsBeforeFieldInit") {
+ // There is a discrepancy between the way linker and the analyzer represent the location of the error,
+ // linker will point to the method caller and the analyzer will point to a line of code.
+ // The TestTypeIsBeforeFieldInit scenario is supported by the analyzer, just the diagnostic message is different
+ // We verify the analyzer generating the right diagnostic in RequiresUnreferencedCodeAnalyzerTests.cs
return;
}
diff --git a/test/ILLink.RoslynAnalyzer.Tests/TestCaseUtils.cs b/test/ILLink.RoslynAnalyzer.Tests/TestCaseUtils.cs
index 60da38b14..3cbd86332 100644
--- a/test/ILLink.RoslynAnalyzer.Tests/TestCaseUtils.cs
+++ b/test/ILLink.RoslynAnalyzer.Tests/TestCaseUtils.cs
@@ -57,8 +57,6 @@ namespace ILLink.RoslynAnalyzer.Tests
case "ExpectedWarning":
case "LogContains":
case "LogDoesNotContain":
- return attr.Ancestors ().OfType<MemberDeclarationSyntax> ().First ().IsKind (SyntaxKind.MethodDeclaration);
-
case "UnrecognizedReflectionAccessPattern":
return true;
}
@@ -71,8 +69,13 @@ namespace ILLink.RoslynAnalyzer.Tests
public static void RunTest<TAnalyzer> (MemberDeclarationSyntax m, List<AttributeSyntax> attrs, params (string, string)[] MSBuildProperties)
where TAnalyzer : DiagnosticAnalyzer, new()
{
+ var testSyntaxTree = m.SyntaxTree.GetRoot ().SyntaxTree;
+ var testDependenciesSource = GetTestDependencies (testSyntaxTree)
+ .Select (testDependency => CSharpSyntaxTree.ParseText (File.ReadAllText (testDependency)));
+
var test = new TestChecker (m, CSharpAnalyzerVerifier<TAnalyzer>
- .CreateCompilation (m.SyntaxTree.GetRoot ().SyntaxTree, MSBuildProperties).Result);
+ .CreateCompilation (testSyntaxTree, MSBuildProperties, additionalSources: testDependenciesSource).Result);
+
test.ValidateAttributes (attrs);
}
@@ -171,7 +174,6 @@ namespace ILLink.RoslynAnalyzer.Tests
public static IEnumerable<string> GetTestFiles ()
{
GetDirectoryPaths (out var rootSourceDir, out _);
-
foreach (var subDir in Directory.EnumerateDirectories (rootSourceDir, "*", SearchOption.AllDirectories)) {
var subDirName = Path.GetFileName (subDir);
switch (subDirName) {
@@ -200,5 +202,21 @@ namespace ILLink.RoslynAnalyzer.Tests
string ThisFile ([CallerFilePath] string path = "") => path;
}
+
+ public static IEnumerable<string> GetTestDependencies (SyntaxTree testSyntaxTree)
+ {
+ GetDirectoryPaths (out var rootSourceDir, out _);
+ foreach (var attribute in testSyntaxTree.GetRoot ().DescendantNodes ().OfType<AttributeSyntax> ()) {
+ if (attribute.Name.ToString () != "SetupCompileBefore")
+ continue;
+
+ var testNamespace = testSyntaxTree.GetRoot ().DescendantNodes ().OfType<NamespaceDeclarationSyntax> ().Single ().Name.ToString ();
+ var testSuiteName = testNamespace.Substring (testNamespace.LastIndexOf ('.') + 1);
+ var args = GetAttributeArguments (attribute);
+ string outputName = GetStringFromExpression (args["#0"]);
+ foreach (var sourceFile in ((ImplicitArrayCreationExpressionSyntax) args["#1"]).DescendantNodes ().OfType<LiteralExpressionSyntax> ())
+ yield return Path.Combine (rootSourceDir, testSuiteName, GetStringFromExpression (sourceFile));
+ }
+ }
}
}
diff --git a/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs b/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs
index 98cc1e4ba..eb6a8eef5 100644
--- a/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs
+++ b/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs
@@ -64,8 +64,10 @@ namespace ILLink.RoslynAnalyzer.Tests
if (!expectedWarningCode.StartsWith ("IL"))
return;
- if (args.TryGetValue ("GlobalAnalysisOnly", out var globalAnalysisOnly) &&
- globalAnalysisOnly is LiteralExpressionSyntax { Token: { Value: true } })
+ if (args.TryGetValue ("ProducedBy", out var producedBy) &&
+ producedBy is MemberAccessExpressionSyntax memberAccessExpression &&
+ memberAccessExpression.Name is IdentifierNameSyntax identifierNameSyntax &&
+ identifierNameSyntax.Identifier.ValueText == "Trimmer")
return;
List<string> expectedMessages = args
diff --git a/test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpAnalyzerVerifier`1.cs b/test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpAnalyzerVerifier`1.cs
index a5777675b..a503bbe70 100644
--- a/test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpAnalyzerVerifier`1.cs
+++ b/test/ILLink.RoslynAnalyzer.Tests/Verifiers/CSharpAnalyzerVerifier`1.cs
@@ -37,22 +37,26 @@ namespace ILLink.RoslynAnalyzer.Tests
public static Task<(CompilationWithAnalyzers Compilation, SemanticModel SemanticModel)> CreateCompilation (
string src,
(string, string)[]? globalAnalyzerOptions = null,
- IEnumerable<MetadataReference>? additionalReferences = null)
- => CreateCompilation (CSharpSyntaxTree.ParseText (src), globalAnalyzerOptions, additionalReferences);
+ IEnumerable<MetadataReference>? additionalReferences = null,
+ IEnumerable<SyntaxTree>? additionalSources = null)
+ => CreateCompilation (CSharpSyntaxTree.ParseText (src), globalAnalyzerOptions, additionalReferences, additionalSources);
- public static async Task<Compilation> GetCompilation (string source, IEnumerable<MetadataReference>? additionalReferences = null)
+ public static async Task<Compilation> GetCompilation (string source, IEnumerable<MetadataReference>? additionalReferences = null, IEnumerable<SyntaxTree>? additionalSources = null)
=> (await CSharpAnalyzerVerifier<RequiresAssemblyFilesAnalyzer>.CreateCompilation (source, additionalReferences: additionalReferences ?? Array.Empty<MetadataReference> ())).Compilation.Compilation;
public static async Task<(CompilationWithAnalyzers Compilation, SemanticModel SemanticModel)> CreateCompilation (
SyntaxTree src,
(string, string)[]? globalAnalyzerOptions = null,
- IEnumerable<MetadataReference>? additionalReferences = null)
+ IEnumerable<MetadataReference>? additionalReferences = null,
+ IEnumerable<SyntaxTree>? additionalSources = null)
{
var mdRef = MetadataReference.CreateFromFile (typeof (Mono.Linker.Tests.Cases.Expectations.Metadata.BaseMetadataAttribute).Assembly.Location);
additionalReferences ??= Array.Empty<MetadataReference> ();
+ var sources = new List<SyntaxTree> () { src };
+ sources.AddRange (additionalSources ?? Array.Empty<SyntaxTree> ());
var comp = CSharpCompilation.Create (
assemblyName: Guid.NewGuid ().ToString ("N"),
- syntaxTrees: new SyntaxTree[] { src },
+ syntaxTrees: sources,
references: (await TestCaseUtils.GetNet6References ()).Add (mdRef).AddRange (additionalReferences),
new CSharpCompilationOptions (OutputKind.DynamicallyLinkedLibrary));
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedWarningAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedWarningAttribute.cs
index 5f2fc633e..02376d513 100644
--- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedWarningAttribute.cs
+++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedWarningAttribute.cs
@@ -16,8 +16,11 @@ namespace Mono.Linker.Tests.Cases.Expectations.Assertions
public int SourceLine { get; set; }
public int SourceColumn { get; set; }
- // Set to true if the warning only applies to global analysis (ILLinker, as opposed to Roslyn Analyzer)
- public bool GlobalAnalysisOnly { get; set; }
+ /// <summary>
+ /// Property used by the result checkers of trimmer and analyzers to determine whether
+ /// the tool should have produced the specified warning on the annotated member.
+ /// </summary>
+ public ProducedBy ProducedBy { get; set; } = ProducedBy.TrimmerAndAnalyzer;
public bool CompilerGeneratedCode { get; set; }
}
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ProducedBy.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ProducedBy.cs
new file mode 100644
index 000000000..1277f897b
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ProducedBy.cs
@@ -0,0 +1,16 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+namespace Mono.Linker.Tests.Cases.Expectations.Assertions
+{
+ [Flags]
+ public enum ProducedBy
+ {
+ Trimmer = 1,
+ Analyzer = 2,
+ TrimmerAndAnalyzer = Trimmer | Analyzer
+ }
+} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/Dependencies/RequiresUnreferencedCodeOnAttributeCtorAttribute.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/Dependencies/RequiresUnreferencedCodeOnAttributeCtorAttribute.cs
new file mode 100644
index 000000000..71dfb798a
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/Dependencies/RequiresUnreferencedCodeOnAttributeCtorAttribute.cs
@@ -0,0 +1,17 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Diagnostics.CodeAnalysis;
+
+namespace Mono.Linker.Tests.Cases.RequiresCapability.Dependencies
+{
+ public class RequiresUnreferencedCodeOnAttributeCtorAttribute : Attribute
+ {
+ [RequiresUnreferencedCode ("Message from attribute's ctor.")]
+ public RequiresUnreferencedCodeOnAttributeCtorAttribute ()
+ {
+ }
+ }
+} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeCapability.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeCapability.cs
index 5d137cbfc..97709abff 100644
--- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeCapability.cs
+++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeCapability.cs
@@ -38,10 +38,10 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
[ExpectedNoWarnings]
public class RequiresUnreferencedCodeCapability
{
- [ExpectedWarning ("IL2026", "--IDerivedInterface.MethodInDerivedInterface--", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "--DynamicallyAccessedTypeWithRequiresUnreferencedCode.RequiresUnreferencedCode--", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "--BaseType.VirtualMethodRequiresUnreferencedCode--", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "--IBaseInterface.MethodInBaseInterface--", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "--IDerivedInterface.MethodInDerivedInterface--", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "--DynamicallyAccessedTypeWithRequiresUnreferencedCode.RequiresUnreferencedCode--", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "--BaseType.VirtualMethodRequiresUnreferencedCode--", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "--IBaseInterface.MethodInBaseInterface--", ProducedBy = ProducedBy.Trimmer)]
public static void Main ()
{
TestRequiresWithMessageOnlyOnMethod ();
@@ -256,7 +256,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
// The second attribute is added through link attribute XML
[RequiresUnreferencedCode ("Message for --MethodWithDuplicateRequiresAttribute--")]
- [ExpectedWarning ("IL2027", "RequiresUnreferencedCodeAttribute", nameof (MethodWithDuplicateRequiresAttribute), GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2027", "RequiresUnreferencedCodeAttribute", nameof (MethodWithDuplicateRequiresAttribute), ProducedBy = ProducedBy.Trimmer)]
static void MethodWithDuplicateRequiresAttribute ()
{
}
@@ -266,7 +266,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
{
}
- [ExpectedWarning ("IL2026", "--RequiresUnreferencedCodeOnlyThroughReflection--", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "--RequiresUnreferencedCodeOnlyThroughReflection--", ProducedBy = ProducedBy.Trimmer)]
static void TestRequiresUnreferencedCodeOnlyThroughReflection ()
{
typeof (RequiresUnreferencedCodeCapability)
@@ -281,7 +281,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
{
}
- [ExpectedWarning ("IL2026", "--GenericType.RequiresUnreferencedCodeOnlyThroughReflection--", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "--GenericType.RequiresUnreferencedCodeOnlyThroughReflection--", ProducedBy = ProducedBy.Trimmer)]
public static void Test ()
{
typeof (AccessedThroughReflectionOnGenericType<T>)
@@ -352,7 +352,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class StaticCtor
{
- [ExpectedWarning ("IL2116", "StaticCtor..cctor()")]
+ [ExpectedWarning ("IL2116", "StaticCtor..cctor()", ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("Message for --TestStaticCtor--")]
static StaticCtor ()
{
@@ -366,7 +366,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class StaticCtorTriggeredByFieldAccess
{
- [ExpectedWarning ("IL2116", "StaticCtorTriggeredByFieldAccess..cctor()")]
+ [ExpectedWarning ("IL2116", "StaticCtorTriggeredByFieldAccess..cctor()", ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("Message for --StaticCtorTriggeredByFieldAccess.Cctor--")]
static StaticCtorTriggeredByFieldAccess ()
{
@@ -383,7 +383,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
struct StaticCCtorForFieldAccess
{
- [ExpectedWarning ("IL2116", "StaticCCtorForFieldAccess..cctor()")]
+ [ExpectedWarning ("IL2116", "StaticCCtorForFieldAccess..cctor()", ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("Message for --StaticCCtorForFieldAccess.cctor--")]
static StaticCCtorForFieldAccess () { }
@@ -414,7 +414,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class StaticCtorTriggeredByMethodCall
{
- [ExpectedWarning ("IL2116", "StaticCtorTriggeredByMethodCall..cctor()")]
+ [ExpectedWarning ("IL2116", "StaticCtorTriggeredByMethodCall..cctor()", ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("Message for --StaticCtorTriggeredByMethodCall.Cctor--")]
static StaticCtorTriggeredByMethodCall ()
{
@@ -497,14 +497,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
// Doesn't work in the analyzer because the test infra for analyzer will not build the second assembly
// and provide it as a ref assembly to the compilation - so the analyzer actually sees the below
// as errors (missing assembly).
- [ExpectedWarning ("IL2026", "--Method--", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "--Method--", ProducedBy = ProducedBy.Trimmer)]
static void TestRequiresInMethodFromCopiedAssembly ()
{
var tmp = new RequiresUnreferencedCodeInCopyAssembly ();
tmp.Method ();
}
- [ExpectedWarning ("IL2026", "--MethodCalledThroughReflection--", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "--MethodCalledThroughReflection--", ProducedBy = ProducedBy.Trimmer)]
static void TestRequiresThroughReflectionInMethodFromCopiedAssembly ()
{
typeof (RequiresUnreferencedCodeInCopyAssembly)
@@ -555,7 +555,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
{
class ClassWithRequiresUnreferencedCodeOnStaticConstructor
{
- [ExpectedWarning ("IL2116")]
+ [ExpectedWarning ("IL2116", ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("This attribute shouldn't be allowed")]
static ClassWithRequiresUnreferencedCodeOnStaticConstructor () { }
}
@@ -597,8 +597,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
public static void TestMethod () { }
}
- // https://github.com/dotnet/linker/issues/2094 - should be supported by the analyzer
- [ExpectedWarning ("IL2026", "--AttributeWhichRequiresUnreferencedCodeAttribute.ctor--", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "--AttributeWhichRequiresUnreferencedCodeAttribute.ctor--")]
static void GenericMethodWithAttributedParameter<[AttributeWhichRequiresUnreferencedCode] T> () { }
static void TestRequiresOnAttributeOnGenericParameter ()
@@ -607,8 +606,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
GenericMethodWithAttributedParameter<int> ();
}
- // https://github.com/dotnet/linker/issues/2094 - should be supported by the analyzer
- [ExpectedWarning ("IL2026", "--AttributeWhichRequiresUnreferencedCodeAttribute.ctor--", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "--AttributeWhichRequiresUnreferencedCodeAttribute.ctor--")]
[ExpectedWarning ("IL2026", "--AttributeWhichRequiresUnreferencedCodeOnPropertyAttribute.PropertyWhichRequires--")]
[AttributeWhichRequiresUnreferencedCode]
[AttributeWhichRequiresUnreferencedCodeOnProperty (PropertyWhichRequires = true)]
@@ -616,8 +614,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
{
}
- // https://github.com/dotnet/linker/issues/2094 - should be supported by the analyzer
- [ExpectedWarning ("IL2026", "--AttributeWhichRequiresUnreferencedCodeAttribute.ctor--", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "--AttributeWhichRequiresUnreferencedCodeAttribute.ctor--")]
[ExpectedWarning ("IL2026", "--AttributeWhichRequiresUnreferencedCodeOnPropertyAttribute.PropertyWhichRequires--")]
[AttributeWhichRequiresUnreferencedCode]
[AttributeWhichRequiresUnreferencedCodeOnProperty (PropertyWhichRequires = true)]
@@ -734,13 +731,13 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
public PInvokeReturnType () { }
}
- // https://github.com/dotnet/linker/issues/2116
- [ExpectedWarning ("IL2026", "--PInvokeReturnType.ctor--", GlobalAnalysisOnly = true)]
+ // https://github.com/mono/linker/issues/2116
+ [ExpectedWarning ("IL2026", "--PInvokeReturnType.ctor--", ProducedBy = ProducedBy.Trimmer)]
[DllImport ("nonexistent")]
static extern PInvokeReturnType PInvokeReturnsType ();
// Analyzer doesn't support IL2050 yet
- [ExpectedWarning ("IL2050", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2050", ProducedBy = ProducedBy.Trimmer)]
public static void Test ()
{
PInvokeReturnsType ();
@@ -877,7 +874,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
public static void MethodWithRUC () { }
}
- [ExpectedWarning ("IL2109", "RequiresOnClass/DerivedWithoutRequires", "RequiresOnClass.ClassWithRequiresUnreferencedCode", "--ClassWithRequiresUnreferencedCode--")]
+ [ExpectedWarning ("IL2109", "RequiresOnClass/DerivedWithoutRequires", "RequiresOnClass.ClassWithRequiresUnreferencedCode", "--ClassWithRequiresUnreferencedCode--", ProducedBy = ProducedBy.Trimmer)]
private class DerivedWithoutRequires : ClassWithRequiresUnreferencedCode
{
public static void StaticMethodInInheritedClass () { }
@@ -929,7 +926,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
}
- [ExpectedWarning ("IL2026", "RequiresOnClass.StaticCtor.StaticCtor()", "Message for --StaticCtor--", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "RequiresOnClass.StaticCtor.StaticCtor()", "Message for --StaticCtor--", ProducedBy = ProducedBy.Trimmer)]
static void TestStaticCctorRequiresUnreferencedCode ()
{
_ = new StaticCtor ();
@@ -946,13 +943,13 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
public static int field;
}
- [ExpectedWarning ("IL2026", "StaticCtorTriggeredByFieldAccess.field", "Message for --StaticCtorTriggeredByFieldAccess--", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "StaticCtorTriggeredByFieldAccess.field", "Message for --StaticCtorTriggeredByFieldAccess--", ProducedBy = ProducedBy.Trimmer)]
static void TestStaticCtorMarkingIsTriggeredByFieldAccessWrite ()
{
StaticCtorTriggeredByFieldAccess.field = 1;
}
- [ExpectedWarning ("IL2026", "StaticCtorTriggeredByFieldAccess.field", "Message for --StaticCtorTriggeredByFieldAccess--", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "StaticCtorTriggeredByFieldAccess.field", "Message for --StaticCtorTriggeredByFieldAccess--", ProducedBy = ProducedBy.Trimmer)]
static void TestStaticCtorMarkingTriggeredOnSecondAccessWrite ()
{
StaticCtorTriggeredByFieldAccess.field = 2;
@@ -976,7 +973,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
public static int field = 42;
}
- [ExpectedWarning ("IL2026", "StaticCCtorTriggeredByFieldAccessRead.field", "Message for --StaticCCtorTriggeredByFieldAccessRead--", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "StaticCCtorTriggeredByFieldAccessRead.field", "Message for --StaticCCtorTriggeredByFieldAccessRead--", ProducedBy = ProducedBy.Trimmer)]
static void TestStaticCtorMarkingIsTriggeredByFieldAccessRead ()
{
var _ = StaticCCtorTriggeredByFieldAccessRead.field;
@@ -994,7 +991,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
}
- [ExpectedWarning ("IL2026", "StaticCtorTriggeredByCtorCalls.StaticCtorTriggeredByCtorCalls()", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "StaticCtorTriggeredByCtorCalls.StaticCtorTriggeredByCtorCalls()", ProducedBy = ProducedBy.Trimmer)]
static void TestStaticCtorTriggeredByCtorCall ()
{
new StaticCtorTriggeredByCtorCalls ();
@@ -1006,7 +1003,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
public int field = 42;
}
- [ExpectedWarning ("IL2026", "ClassWithInstanceField.ClassWithInstanceField()", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "ClassWithInstanceField.ClassWithInstanceField()", ProducedBy = ProducedBy.Trimmer)]
static void TestInstanceFieldCallDontWarn ()
{
ClassWithInstanceField instance = new ClassWithInstanceField ();
@@ -1049,7 +1046,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
// A nested class is not considered a static method nor constructor therefore RequiresUnreferencedCode doesnt apply
// and this warning is not suppressed
- [ExpectedWarning ("IL2109", "RequiresOnClass/DerivedWithRequires2/DerivedNestedClass", "--ClassWithRequiresUnreferencedCode--")]
+ [ExpectedWarning ("IL2109", "RequiresOnClass/DerivedWithRequires2/DerivedNestedClass", "--ClassWithRequiresUnreferencedCode--", ProducedBy = ProducedBy.Trimmer)]
public class DerivedNestedClass : ClassWithRequiresUnreferencedCode
{
public static void NestedStaticMethod () { }
@@ -1106,13 +1103,13 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
}
- [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequiresUnreferencedCode.StaticMethod()", "--ClassWithRequiresUnreferencedCode--", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequiresUnreferencedCode.StaticMethod()", "--ClassWithRequiresUnreferencedCode--", ProducedBy = ProducedBy.Trimmer)]
static void TestRequiresInClassAccessedByStaticMethod ()
{
ClassWithRequiresUnreferencedCode.StaticMethod ();
}
- [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequiresUnreferencedCode", "--ClassWithRequiresUnreferencedCode--", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequiresUnreferencedCode", "--ClassWithRequiresUnreferencedCode--", ProducedBy = ProducedBy.Trimmer)]
static void TestRequiresInClassAccessedByCctor ()
{
var classObject = new ClassWithRequiresUnreferencedCode ();
@@ -1123,10 +1120,10 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
ClassWithRequiresUnreferencedCode.NestedClass.NestedStaticMethod ();
}
- [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequiresUnreferencedCode.StaticMethod()", "--ClassWithRequiresUnreferencedCode--", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequiresUnreferencedCode.StaticMethod()", "--ClassWithRequiresUnreferencedCode--", ProducedBy = ProducedBy.Trimmer)]
// Although we suppress the warning from RequiresOnMethod.MethodWithRUC () we still get a warning because we call CallRUCMethod() which is an static method on a type with RUC
- [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequiresUnreferencedCode.CallRUCMethod()", "--ClassWithRequiresUnreferencedCode--", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "ClassWithRequiresUnreferencedCode.Instance", "--ClassWithRequiresUnreferencedCode--", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequiresUnreferencedCode.CallRUCMethod()", "--ClassWithRequiresUnreferencedCode--", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "ClassWithRequiresUnreferencedCode.Instance", "--ClassWithRequiresUnreferencedCode--", ProducedBy = ProducedBy.Trimmer)]
static void TestRequiresOnBaseButNotOnDerived ()
{
DerivedWithoutRequires.StaticMethodInInheritedClass ();
@@ -1140,7 +1137,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
DerivedWithoutRequires2.StaticMethod ();
}
- [ExpectedWarning ("IL2026", "RequiresOnClass.DerivedWithRequires.StaticMethodInInheritedClass()", "--DerivedWithRequires--", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "RequiresOnClass.DerivedWithRequires.StaticMethodInInheritedClass()", "--DerivedWithRequires--", ProducedBy = ProducedBy.Trimmer)]
static void TestRequiresOnDerivedButNotOnBase ()
{
DerivedWithRequires.StaticMethodInInheritedClass ();
@@ -1149,8 +1146,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
DerivedWithRequires.NestedClass.NestedStaticMethod ();
}
- [ExpectedWarning ("IL2026", "RequiresOnClass.DerivedWithRequires2.StaticMethodInInheritedClass()", "--DerivedWithRequires2--", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequiresUnreferencedCode.StaticMethod()", "--ClassWithRequiresUnreferencedCode--", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "RequiresOnClass.DerivedWithRequires2.StaticMethodInInheritedClass()", "--DerivedWithRequires2--", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequiresUnreferencedCode.StaticMethod()", "--ClassWithRequiresUnreferencedCode--", ProducedBy = ProducedBy.Trimmer)]
static void TestRequiresOnBaseAndDerived ()
{
DerivedWithRequires2.StaticMethodInInheritedClass ();
@@ -1159,7 +1156,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
DerivedWithRequires2.NestedClass.NestedStaticMethod ();
}
- [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequiresUnreferencedCode.TestSuppressions(Type[])", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "RequiresOnClass.ClassWithRequiresUnreferencedCode.TestSuppressions(Type[])", ProducedBy = ProducedBy.Trimmer)]
static void TestSuppressionsOnClass ()
{
ClassWithRequiresUnreferencedCode.TestSuppressions (new[] { typeof (ClassWithRequiresUnreferencedCode) });
@@ -1196,15 +1193,15 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
public static int field;
public static int Property { get; set; }
- // These should not be reported https://github.com/dotnet/linker/issues/2218
- [ExpectedWarning ("IL2026", "add_Event", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "remove_Event", GlobalAnalysisOnly = true)]
+ // These should not be reported https://github.com/mono/linker/issues/2218
+ [ExpectedWarning ("IL2026", "add_Event", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "remove_Event", ProducedBy = ProducedBy.Trimmer)]
public static event EventHandler Event;
}
- [ExpectedWarning ("IL2026", "MemberTypesWithRUC.field", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "MemberTypesWithRUC.Property.set", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "MemberTypesWithRUC.remove_Event", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "MemberTypesWithRUC.field", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "MemberTypesWithRUC.Property.set", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "MemberTypesWithRUC.remove_Event", ProducedBy = ProducedBy.Trimmer)]
static void TestOtherMemberTypesWithRUC ()
{
MemberTypesWithRUC.field = 1;
@@ -1215,10 +1212,10 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class ReflectionAccessOnMethod
{
// Analyzer still dont understand RUC on type
- [ExpectedWarning ("IL2026", "BaseWithoutRequiresOnType.Method()", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "InterfaceWithoutRequires.Method(Int32)", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "InterfaceWithoutRequires.Method()", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "ImplementationWithRequiresOnType.Method()", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "BaseWithoutRequiresOnType.Method()", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "InterfaceWithoutRequires.Method(Int32)", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "InterfaceWithoutRequires.Method()", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "ImplementationWithRequiresOnType.Method()", ProducedBy = ProducedBy.Trimmer)]
static void TestDAMAccess ()
{
// Warns because BaseWithoutRequiresOnType.Method as RUC on the method
@@ -1240,10 +1237,10 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
typeof (DerivedWithoutRequiresOnType).RequiresPublicMethods ();
}
- [ExpectedWarning ("IL2026", "BaseWithoutRequiresOnType.Method()", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "InterfaceWithoutRequires.Method(Int32)", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "InterfaceWithoutRequires.Method()", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "ImplementationWithRequiresOnType.Method()", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "BaseWithoutRequiresOnType.Method()", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "InterfaceWithoutRequires.Method(Int32)", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "InterfaceWithoutRequires.Method()", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "ImplementationWithRequiresOnType.Method()", ProducedBy = ProducedBy.Trimmer)]
static void TestDirectReflectionAccess ()
{
// RUC on the method itself
@@ -1274,10 +1271,10 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
public BaseWithRUC () { }
}
- [ExpectedWarning ("IL2109", "ReflectionAccessOnCtor/DerivedWithoutRUC", "ReflectionAccessOnCtor.BaseWithRUC", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2109", "ReflectionAccessOnCtor/DerivedWithoutRUC", "ReflectionAccessOnCtor.BaseWithRUC", ProducedBy = ProducedBy.Trimmer)]
class DerivedWithoutRUC : BaseWithRUC
{
- [ExpectedWarning ("IL2026", "--BaseWithRUC--")] // The body has direct call to the base.ctor()
+ [ExpectedWarning ("IL2026", "--BaseWithRUC--", ProducedBy = ProducedBy.Trimmer)] // The body has direct call to the base.ctor()
public DerivedWithoutRUC () { }
}
@@ -1296,9 +1293,9 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
public DerivedWithRUCOnBaseWithoutRuc () { }
}
- [ExpectedWarning ("IL2026", "BaseWithRUC.BaseWithRUC()", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "DerivedWithRUCOnBaseWithRUC.DerivedWithRUCOnBaseWithRUC()", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "DerivedWithRUCOnBaseWithoutRuc.DerivedWithRUCOnBaseWithoutRuc()", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "BaseWithRUC.BaseWithRUC()", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "DerivedWithRUCOnBaseWithRUC.DerivedWithRUCOnBaseWithRUC()", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "DerivedWithRUCOnBaseWithoutRuc.DerivedWithRUCOnBaseWithoutRuc()", ProducedBy = ProducedBy.Trimmer)]
static void TestDAMAccess ()
{
// Warns because the type has RUC
@@ -1314,9 +1311,9 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
typeof (DerivedWithRUCOnBaseWithoutRuc).RequiresPublicConstructors ();
}
- [ExpectedWarning ("IL2026", "BaseWithRUC.BaseWithRUC()", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "DerivedWithRUCOnBaseWithRUC.DerivedWithRUCOnBaseWithRUC()", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "DerivedWithRUCOnBaseWithoutRuc.DerivedWithRUCOnBaseWithoutRuc()", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "BaseWithRUC.BaseWithRUC()", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "DerivedWithRUCOnBaseWithRUC.DerivedWithRUCOnBaseWithRUC()", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "DerivedWithRUCOnBaseWithoutRuc.DerivedWithRUCOnBaseWithoutRuc()", ProducedBy = ProducedBy.Trimmer)]
static void TestDirectReflectionAccess ()
{
typeof (BaseWithRUC).GetConstructor (Type.EmptyTypes);
@@ -1348,7 +1345,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
public int InstnaceField;
}
- [ExpectedWarning ("IL2109", "ReflectionAccessOnField/DerivedWithoutRUC", "ReflectionAccessOnField.WithRUC", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2109", "ReflectionAccessOnField/DerivedWithoutRUC", "ReflectionAccessOnField.WithRUC", ProducedBy = ProducedBy.Trimmer)]
class DerivedWithoutRUC : WithRUC
{
public static int DerivedStaticField;
@@ -1360,9 +1357,9 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
public static int DerivedStaticField;
}
- [ExpectedWarning ("IL2026", "WithRUC.StaticField", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "WithRUC.PrivateStaticField", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "DerivedWithRUC.DerivedStaticField", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "WithRUC.StaticField", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "WithRUC.PrivateStaticField", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "DerivedWithRUC.DerivedStaticField", ProducedBy = ProducedBy.Trimmer)]
static void TestDAMAccess ()
{
typeof (WithRUC).RequiresPublicFields ();
@@ -1372,9 +1369,9 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
typeof (DerivedWithRUC).RequiresPublicFields ();
}
- [ExpectedWarning ("IL2026", "WithRUC.StaticField", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "WithRUC.PrivateStaticField", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "DerivedWithRUC.DerivedStaticField", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "WithRUC.StaticField", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "WithRUC.PrivateStaticField", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "DerivedWithRUC.DerivedStaticField", ProducedBy = ProducedBy.Trimmer)]
static void TestDirectReflectionAccess ()
{
typeof (WithRUC).GetField (nameof (WithRUC.StaticField));
@@ -1385,11 +1382,11 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
typeof (DerivedWithRUC).GetField (nameof (DerivedWithRUC.DerivedStaticField));
}
- [ExpectedWarning ("IL2026", "WithRUC.StaticField", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "WithRUC.StaticField", ProducedBy = ProducedBy.Trimmer)]
[DynamicDependency (nameof (WithRUC.StaticField), typeof (WithRUC))]
[DynamicDependency (nameof (WithRUC.InstanceField), typeof (WithRUC))] // Doesn't warn
[DynamicDependency (DynamicallyAccessedMemberTypes.PublicFields, typeof (DerivedWithoutRUC))] // Doesn't warn
- [ExpectedWarning ("IL2026", "DerivedWithRUC.DerivedStaticField", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "DerivedWithRUC.DerivedStaticField", ProducedBy = ProducedBy.Trimmer)]
[DynamicDependency (DynamicallyAccessedMemberTypes.PublicFields, typeof (DerivedWithRUC))]
static void TestDynamicDependencyAccess ()
{
@@ -1403,13 +1400,13 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)]
[RequiresUnreferencedCode ("This class is dangerous")]
- [ExpectedWarning ("IL2113", "BaseForDAMAnnotatedClass.baseField", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2113", "BaseForDAMAnnotatedClass.baseField", ProducedBy = ProducedBy.Trimmer)]
class DAMAnnotatedClass : BaseForDAMAnnotatedClass
{
- [ExpectedWarning ("IL2112", "DAMAnnotatedClass.publicField", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2112", "DAMAnnotatedClass.publicField", ProducedBy = ProducedBy.Trimmer)]
public static int publicField;
- [ExpectedWarning ("IL2112", "DAMAnnotatedClass.privatefield", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2112", "DAMAnnotatedClass.privatefield", ProducedBy = ProducedBy.Trimmer)]
static int privatefield;
}
@@ -1436,13 +1433,13 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class WithRUC
{
// These should be reported only in TestDirectReflectionAccess
- // https://github.com/dotnet/linker/issues/2218
- [ExpectedWarning ("IL2026", "add_StaticEvent", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "remove_StaticEvent", GlobalAnalysisOnly = true)]
+ // https://github.com/mono/linker/issues/2218
+ [ExpectedWarning ("IL2026", "add_StaticEvent", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "remove_StaticEvent", ProducedBy = ProducedBy.Trimmer)]
public static event EventHandler StaticEvent;
}
- [ExpectedWarning ("IL2026", "add_StaticEvent", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "add_StaticEvent", ProducedBy = ProducedBy.Trimmer)]
static void TestDirectReflectionAccess ()
{
typeof (WithRUC).GetEvent (nameof (WithRUC.StaticEvent));
@@ -1470,7 +1467,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
public int InstnaceProperty { get; set; }
}
- [ExpectedWarning ("IL2109", "ReflectionAccessOnProperties/DerivedWithoutRUC", "ReflectionAccessOnProperties.WithRUC", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2109", "ReflectionAccessOnProperties/DerivedWithoutRUC", "ReflectionAccessOnProperties.WithRUC", ProducedBy = ProducedBy.Trimmer)]
class DerivedWithoutRUC : WithRUC
{
public static int DerivedStaticProperty { get; set; }
@@ -1482,12 +1479,12 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
public static int DerivedStaticProperty { get; set; }
}
- [ExpectedWarning ("IL2026", "WithRUC.StaticProperty.get", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "WithRUC.StaticProperty.set", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "WithRUC.PrivateStaticProperty.get", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "WithRUC.PrivateStaticProperty.set", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "DerivedWithRUC.DerivedStaticProperty.get", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "DerivedWithRUC.DerivedStaticProperty.set", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "WithRUC.StaticProperty.get", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "WithRUC.StaticProperty.set", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "WithRUC.PrivateStaticProperty.get", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "WithRUC.PrivateStaticProperty.set", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "DerivedWithRUC.DerivedStaticProperty.get", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "DerivedWithRUC.DerivedStaticProperty.set", ProducedBy = ProducedBy.Trimmer)]
static void TestDAMAccess ()
{
typeof (WithRUC).RequiresPublicProperties ();
@@ -1497,12 +1494,12 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
typeof (DerivedWithRUC).RequiresPublicProperties ();
}
- [ExpectedWarning ("IL2026", "WithRUC.StaticProperty.get", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "WithRUC.StaticProperty.set", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "WithRUC.PrivateStaticProperty.get", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "WithRUC.PrivateStaticProperty.set", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "DerivedWithRUC.DerivedStaticProperty.get", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "DerivedWithRUC.DerivedStaticProperty.set", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "WithRUC.StaticProperty.get", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "WithRUC.StaticProperty.set", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "WithRUC.PrivateStaticProperty.get", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "WithRUC.PrivateStaticProperty.set", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "DerivedWithRUC.DerivedStaticProperty.get", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "DerivedWithRUC.DerivedStaticProperty.set", ProducedBy = ProducedBy.Trimmer)]
static void TestDirectReflectionAccess ()
{
typeof (WithRUC).GetProperty (nameof (WithRUC.StaticProperty));
@@ -1513,13 +1510,13 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
typeof (DerivedWithRUC).GetProperty (nameof (DerivedWithRUC.DerivedStaticProperty));
}
- [ExpectedWarning ("IL2026", "WithRUC.StaticProperty.get", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "WithRUC.StaticProperty.set", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "WithRUC.StaticProperty.get", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "WithRUC.StaticProperty.set", ProducedBy = ProducedBy.Trimmer)]
[DynamicDependency (nameof (WithRUC.StaticProperty), typeof (WithRUC))]
[DynamicDependency (nameof (WithRUC.InstanceProperty), typeof (WithRUC))] // Doesn't warn
[DynamicDependency (DynamicallyAccessedMemberTypes.PublicProperties, typeof (DerivedWithoutRUC))] // Doesn't warn
- [ExpectedWarning ("IL2026", "DerivedWithRUC.DerivedStaticProperty.get", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2026", "DerivedWithRUC.DerivedStaticProperty.set", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "DerivedWithRUC.DerivedStaticProperty.get", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "DerivedWithRUC.DerivedStaticProperty.set", ProducedBy = ProducedBy.Trimmer)]
[DynamicDependency (DynamicallyAccessedMemberTypes.PublicProperties, typeof (DerivedWithRUC))]
static void TestDynamicDependencyAccess ()
{
@@ -1533,21 +1530,21 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties)]
[RequiresUnreferencedCode ("This class is dangerous")]
- [ExpectedWarning ("IL2113", "BaseForDAMAnnotatedClass.baseProperty.get", GlobalAnalysisOnly = true)]
- [ExpectedWarning ("IL2113", "BaseForDAMAnnotatedClass.baseProperty.set", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2113", "BaseForDAMAnnotatedClass.baseProperty.get", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2113", "BaseForDAMAnnotatedClass.baseProperty.set", ProducedBy = ProducedBy.Trimmer)]
class DAMAnnotatedClass : BaseForDAMAnnotatedClass
{
public static int publicProperty {
- [ExpectedWarning ("IL2112", "DAMAnnotatedClass.publicProperty.get", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2112", "DAMAnnotatedClass.publicProperty.get", ProducedBy = ProducedBy.Trimmer)]
get;
- [ExpectedWarning ("IL2112", "DAMAnnotatedClass.publicProperty.set", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2112", "DAMAnnotatedClass.publicProperty.set", ProducedBy = ProducedBy.Trimmer)]
set;
}
static int privateProperty {
- [ExpectedWarning ("IL2112", "DAMAnnotatedClass.privateProperty.get", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2112", "DAMAnnotatedClass.privateProperty.get", ProducedBy = ProducedBy.Trimmer)]
get;
- [ExpectedWarning ("IL2112", "DAMAnnotatedClass.privateProperty.set", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2112", "DAMAnnotatedClass.privateProperty.set", ProducedBy = ProducedBy.Trimmer)]
set;
}
}
@@ -1581,7 +1578,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[AttributeWithRUC (PropertyOnAttribute = 42)]
- [ExpectedWarning ("IL2026", "AttributeWithRUC.AttributeWithRUC()", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "AttributeWithRUC.AttributeWithRUC()", ProducedBy = ProducedBy.Trimmer)]
static void KeepFieldOnAttribute () { }
public static void Test ()
diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeInCompilerGeneratedCode.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeInCompilerGeneratedCode.cs
index 0bdd62526..1b0548745 100644
--- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeInCompilerGeneratedCode.cs
+++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeInCompilerGeneratedCode.cs
@@ -58,7 +58,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
RequiresUnreferencedCodeMethod ();
}
- [ExpectedWarning ("IL2026", "--RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "--RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
static IEnumerable<int> TestReflectionAccess ()
{
yield return 0;
@@ -76,7 +76,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
var action = new Action (RequiresUnreferencedCodeMethod);
}
- [ExpectedWarning ("IL2026", "--TypeWithRUCMethod.RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "--TypeWithRUCMethod.RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
static IEnumerable<int> TestDynamicallyAccessedMethod ()
{
typeof (TypeWithRUCMethod).RequiresNonPublicMethods ();
@@ -181,7 +181,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
RequiresUnreferencedCodeMethod ();
}
- [ExpectedWarning ("IL2026", "--RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "--RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
static async void TestReflectionAccess ()
{
await MethodAsync ();
@@ -198,7 +198,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
var action = new Action (RequiresUnreferencedCodeMethod);
}
- [ExpectedWarning ("IL2026", "--TypeWithRUCMethod.RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "--TypeWithRUCMethod.RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
static async void TestDynamicallyAccessedMethod ()
{
typeof (TypeWithRUCMethod).RequiresNonPublicMethods ();
@@ -302,7 +302,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
await MethodAsync ();
}
- [ExpectedWarning ("IL2026", "--RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "--RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
static async IAsyncEnumerable<int> TestReflectionAccess ()
{
yield return 0;
@@ -322,7 +322,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
var action = new Action (RequiresUnreferencedCodeMethod);
}
- [ExpectedWarning ("IL2026", "--TypeWithRUCMethod.RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "--TypeWithRUCMethod.RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
static async IAsyncEnumerable<int> TestDynamicallyAccessedMethod ()
{
typeof (TypeWithRUCMethod).RequiresNonPublicMethods ();
@@ -439,7 +439,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
}
- [ExpectedWarning ("IL2026", "--RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "--RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
static void TestReflectionAccess ()
{
LocalFunction ();
@@ -460,7 +460,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
}
- [ExpectedWarning ("IL2026", "--TypeWithRUCMethod.RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "--TypeWithRUCMethod.RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
static void TestDynamicallyAccessedMethod ()
{
LocalFunction ();
@@ -697,7 +697,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
};
}
- [ExpectedWarning ("IL2026", "--RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "--RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
static void TestReflectionAccess ()
{
Action _ = () => {
@@ -715,7 +715,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
};
}
- [ExpectedWarning ("IL2026", "--TypeWithRUCMethod.RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "--TypeWithRUCMethod.RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
static void TestDynamicallyAccessedMethod ()
{
Action _ = () => {
@@ -749,7 +749,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
// The warning is currently not detected by roslyn analyzer since it doesn't analyze DAM yet
- [ExpectedWarning ("IL2067", CompilerGeneratedCode = true, GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2067", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("Suppress in body")]
static void TestCallWithReflectionAnalysisWarning ()
{
@@ -768,7 +768,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
// Analyzer doesn't recognize reflection access - so doesn't warn in this case
- [ExpectedWarning ("IL2026", CompilerGeneratedCode = true, GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("Suppress in body")]
static void TestReflectionAccess ()
{
@@ -789,7 +789,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
// Analyzer doesn't apply DAM - so won't see this warnings
- [ExpectedWarning ("IL2026", CompilerGeneratedCode = true, GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("Suppress in body")]
static void TestDynamicallyAccessedMethod ()
{
@@ -799,7 +799,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
// The warning is currently not detected by roslyn analyzer since it doesn't analyze DAM yet
- [ExpectedWarning ("IL2077", CompilerGeneratedCode = true, GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2077", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("Suppress in body")]
static async void TestMethodParameterWithRequirements (Type unknownType = null)
{
@@ -807,7 +807,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
// The warning is currently not detected by roslyn analyzer since it doesn't analyze DAM yet
- [ExpectedWarning ("IL2091", CompilerGeneratedCode = true, GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2091", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("Suppress in body")]
static void TestGenericMethodParameterRequirement<TUnknown> ()
{
@@ -817,7 +817,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
// The warning is currently not detected by roslyn analyzer since it doesn't analyze DAM yet
- [ExpectedWarning ("IL2091", CompilerGeneratedCode = true, GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2091", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("Suppress in body")]
static void TestGenericTypeParameterRequirement<TUnknown> ()
{
@@ -858,7 +858,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
}
- [ExpectedWarning ("IL2026", "--TypeWithRUCMethod.RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "--TypeWithRUCMethod.RequiresUnreferencedCodeMethod--", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
static IEnumerable<int> TestDynamicallyAccessedMethodViaGenericMethodParameterInIterator ()
{
yield return 1;
@@ -952,7 +952,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
RequiresUnreferencedCodeMethod ();
}
- [ExpectedWarning ("IL2026", "RUC to suppress", GlobalAnalysisOnly = true)]
+ [ExpectedWarning ("IL2026", "RUC to suppress", ProducedBy = ProducedBy.Trimmer)]
public static void Test ()
{
// This is not a 100% reliable test, since in theory it can be marked in any order and so it could happen that the
diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeOnAttributeCtor.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeOnAttributeCtor.cs
new file mode 100644
index 000000000..176b3930b
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresUnreferencedCodeOnAttributeCtor.cs
@@ -0,0 +1,91 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Diagnostics.CodeAnalysis;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Metadata;
+using Mono.Linker.Tests.Cases.RequiresCapability.Dependencies;
+
+namespace Mono.Linker.Tests.Cases.RequiresCapability
+{
+ [SetupLinkerAction ("link", "test.exe")]
+ [SetupCompileBefore ("RUCOnAttributeCtor.dll", new[] { "Dependencies/RequiresUnreferencedCodeOnAttributeCtorAttribute.cs" })]
+ [SkipKeptItemsValidation]
+ [ExpectedNoWarnings]
+ public class RequiresUnreferencedCodeOnAttributeCtor
+ {
+ [ExpectedWarning ("IL2026", "Message from attribute's ctor.")]
+ public static void Main ()
+ {
+ var type = new Type ();
+ type.Method ();
+ type.MethodAnnotatedWithRUC ();
+ type.Field = 0;
+ _ = type.PropertyGetter;
+ type.PropertySetter = 0;
+ type.EventAdd -= (sender, e) => { };
+ type.EventRemove += (sender, e) => { };
+ Type.Interface annotatedInterface = new Type.NestedType ();
+ }
+
+ [ExpectedWarning ("IL2026", "Message from attribute's ctor.")]
+ [RequiresUnreferencedCodeOnAttributeCtor]
+ [KeptMember (".ctor()")]
+ public class Type
+ {
+ [ExpectedWarning ("IL2026", "Message from attribute's ctor.")]
+ [RequiresUnreferencedCodeOnAttributeCtor]
+ public void Method ()
+ {
+ }
+
+ [RequiresUnreferencedCode ("Message from attribute's ctor.")]
+ [RequiresUnreferencedCodeOnAttributeCtor]
+ public void MethodAnnotatedWithRUC ()
+ {
+ }
+
+ [ExpectedWarning ("IL2026", "Message from attribute's ctor.")]
+ [RequiresUnreferencedCodeOnAttributeCtor]
+ public int Field;
+
+ public int PropertyGetter {
+ [ExpectedWarning ("IL2026", "Message from attribute's ctor.")]
+ [RequiresUnreferencedCodeOnAttributeCtor]
+ get { return 0; }
+ }
+
+ public int PropertySetter {
+ [ExpectedWarning ("IL2026", "Message from attribute's ctor.")]
+ [RequiresUnreferencedCodeOnAttributeCtor]
+ set { throw new NotImplementedException (); }
+ }
+
+ public event EventHandler EventAdd {
+ add { }
+ [ExpectedWarning ("IL2026", "Message from attribute's ctor.")]
+ [RequiresUnreferencedCodeOnAttributeCtor]
+ remove { }
+ }
+
+ public event EventHandler EventRemove {
+ [ExpectedWarning ("IL2026", "Message from attribute's ctor.")]
+ [RequiresUnreferencedCodeOnAttributeCtor]
+ add { }
+ remove { }
+ }
+
+ [ExpectedWarning ("IL2026", "Message from attribute's ctor.")]
+ [RequiresUnreferencedCodeOnAttributeCtor]
+ public interface Interface
+ {
+ }
+
+ public class NestedType : Interface
+ {
+ }
+ }
+ }
+}
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
index 94ee84a28..fe2b6bf8e 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
@@ -651,6 +651,11 @@ namespace Mono.Linker.Tests.TestCasesRunner
}
}
+ bool IsProducedByLinker (CustomAttribute attr)
+ {
+ var producedBy = attr.GetPropertyValue ("ProducedBy");
+ return producedBy is null ? true : ((ProducedBy) producedBy).HasFlag (ProducedBy.Trimmer);
+ }
IEnumerable<ICustomAttributeProvider> GetAttributeProviders (AssemblyDefinition assembly)
{
foreach (var testType in assembly.AllDefinedTypes ()) {
@@ -673,6 +678,9 @@ namespace Mono.Linker.Tests.TestCasesRunner
foreach (var attrProvider in GetAttributeProviders (original)) {
bool foundReflectionAccessPatternAttributesToVerify = false;
foreach (var attr in attrProvider.CustomAttributes) {
+ if (!IsProducedByLinker (attr))
+ break;
+
switch (attr.AttributeType.Name) {
case nameof (LogContainsAttribute): {