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:
authorTlakaelel Axayakatl Ceja <tlakaelel.ceja@microsoft.com>2021-11-03 01:50:38 +0300
committerGitHub <noreply@github.com>2021-11-03 01:50:38 +0300
commit8e455f03b6a196ea4096f3eacdcc9b146be1e866 (patch)
treed1ee837ac5e9a2ada18a995e62d7c14e4a85dfbe
parentc702d0337dc1db26a74c482f19a367ad9ddb7b89 (diff)
Test Restructure (#2336)
Move RequiresAssemblyFiles from Analyzer to the linker RequiresCapability file Move the new constraint code from RequiresUnreferencedCode to be on the base Requires file Add Warning Id to messages from the analyzer to distinguish in a test which analyzer missed/found a warning Add RequiresAssemblyFilesMismatchAttribute Title and Message to fix bug Add testing in linker for mismatching attributes Add testing in linker for Delegates in CompilerGenerated file Add support for static constructor compiler-generated calls Add additional warnings from DAM and RUC interaction. Not supported by the analyzer yet
-rw-r--r--src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs46
-rw-r--r--src/ILLink.RoslynAnalyzer/RequiresAssemblyFilesAnalyzer.cs6
-rw-r--r--src/ILLink.RoslynAnalyzer/RequiresUnreferencedCodeAnalyzer.cs56
-rw-r--r--src/ILLink.Shared/DiagnosticId.cs2
-rw-r--r--src/ILLink.Shared/SharedStrings.resx6
-rw-r--r--test/ILLink.RoslynAnalyzer.Tests/LinkerTestCases.cs2
-rw-r--r--test/ILLink.RoslynAnalyzer.Tests/RequiresAssemblyFilesAnalyzerTests.cs555
-rw-r--r--test/ILLink.RoslynAnalyzer.Tests/RequiresUnreferencedCodeAnalyzerTests.cs550
-rw-r--r--test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs2
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Assertions/LogContainsAttribute.cs4
-rw-r--r--test/Mono.Linker.Tests.Cases.Expectations/Assertions/LogDoesNotContainAttribute.cs6
-rw-r--r--test/Mono.Linker.Tests.Cases/RequiresCapability/Dependencies/ReferenceInterfaces.cs44
-rw-r--r--test/Mono.Linker.Tests.Cases/RequiresCapability/Dependencies/RequiresInCopyAssembly.cs13
-rw-r--r--test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapability.cs355
-rw-r--r--test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityFromCopiedAssembly.cs1
-rw-r--r--test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs233
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs3
17 files changed, 716 insertions, 1168 deletions
diff --git a/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs b/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs
index 05e97d464..c57a8aecd 100644
--- a/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs
+++ b/src/ILLink.RoslynAnalyzer/RequiresAnalyzerBase.cs
@@ -8,6 +8,7 @@ using System.Linq;
using ILLink.Shared;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Operations;
@@ -144,6 +145,51 @@ namespace ILLink.RoslynAnalyzer
CheckCalledMember (operationContext, methodSymbol, incompatibleMembers);
}, OperationKind.DelegateCreation);
+ context.RegisterSyntaxNodeAction (syntaxNodeAnalysisContext => {
+ var model = syntaxNodeAnalysisContext.SemanticModel;
+ if (syntaxNodeAnalysisContext.ContainingSymbol is not ISymbol containingSymbol || containingSymbol.HasAttribute (RequiresAttributeName))
+ return;
+
+ GenericNameSyntax genericNameSyntaxNode = (GenericNameSyntax) syntaxNodeAnalysisContext.Node;
+ var typeParams = ImmutableArray<ITypeParameterSymbol>.Empty;
+ var typeArgs = ImmutableArray<ITypeSymbol>.Empty;
+ switch (model.GetSymbolInfo (genericNameSyntaxNode).Symbol) {
+ case INamedTypeSymbol typeSymbol:
+ typeParams = typeSymbol.TypeParameters;
+ typeArgs = typeSymbol.TypeArguments;
+ break;
+
+ case IMethodSymbol methodSymbol:
+ typeParams = methodSymbol.TypeParameters;
+ typeArgs = methodSymbol.TypeArguments;
+ break;
+
+ default:
+ return;
+ }
+
+ for (int i = 0; i < typeParams.Length; i++) {
+ var typeParam = typeParams[i];
+ var typeArg = typeArgs[i];
+ if (!typeParam.HasConstructorConstraint)
+ continue;
+
+ var typeArgCtors = ((INamedTypeSymbol) typeArg).InstanceConstructors;
+ foreach (var instanceCtor in typeArgCtors) {
+ if (instanceCtor.Arity > 0)
+ continue;
+
+ if (instanceCtor.TryGetAttribute (RequiresAttributeName, out var requiresUnreferencedCodeAttribute)) {
+ syntaxNodeAnalysisContext.ReportDiagnostic (Diagnostic.Create (RequiresDiagnosticRule,
+ syntaxNodeAnalysisContext.Node.GetLocation (),
+ containingSymbol.GetDisplayName (),
+ (string) requiresUnreferencedCodeAttribute.ConstructorArguments[0].Value!,
+ GetUrlFromAttribute (requiresUnreferencedCodeAttribute)));
+ }
+ }
+ }
+ }, SyntaxKind.GenericName);
+
// Register any extra operation actions supported by the analyzer.
foreach (var extraOperationAction in ExtraOperationActions)
context.RegisterOperationAction (extraOperationAction.Action, extraOperationAction.OperationKind);
diff --git a/src/ILLink.RoslynAnalyzer/RequiresAssemblyFilesAnalyzer.cs b/src/ILLink.RoslynAnalyzer/RequiresAssemblyFilesAnalyzer.cs
index 146eef064..f2e14ff60 100644
--- a/src/ILLink.RoslynAnalyzer/RequiresAssemblyFilesAnalyzer.cs
+++ b/src/ILLink.RoslynAnalyzer/RequiresAssemblyFilesAnalyzer.cs
@@ -24,9 +24,9 @@ namespace ILLink.RoslynAnalyzer
static readonly DiagnosticDescriptor s_requiresAssemblyFilesRule = DiagnosticDescriptors.GetDiagnosticDescriptor (DiagnosticId.RequiresAssemblyFiles,
helpLinkUri: "https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/il3002");
- static readonly DiagnosticDescriptor s_requiresAssembyFilesAttributeMismatch = DiagnosticDescriptors.GetDiagnosticDescriptor (DiagnosticId.RequiresAssembyFilesAttributeMismatch);
+ static readonly DiagnosticDescriptor s_requiresAssemblyFilesAttributeMismatch = DiagnosticDescriptors.GetDiagnosticDescriptor (DiagnosticId.RequiresAssemblyFilesAttributeMismatch);
- public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create (s_locationRule, s_getFilesRule, s_requiresAssemblyFilesRule, s_requiresAssembyFilesAttributeMismatch);
+ public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create (s_locationRule, s_getFilesRule, s_requiresAssemblyFilesRule, s_requiresAssemblyFilesAttributeMismatch);
private protected override string RequiresAttributeName => RequiresAssemblyFilesAttribute;
@@ -36,7 +36,7 @@ namespace ILLink.RoslynAnalyzer
private protected override DiagnosticDescriptor RequiresDiagnosticRule => s_requiresAssemblyFilesRule;
- private protected override DiagnosticDescriptor RequiresAttributeMismatch => s_requiresAssembyFilesAttributeMismatch;
+ private protected override DiagnosticDescriptor RequiresAttributeMismatch => s_requiresAssemblyFilesAttributeMismatch;
protected override bool IsAnalyzerEnabled (AnalyzerOptions options, Compilation compilation)
{
diff --git a/src/ILLink.RoslynAnalyzer/RequiresUnreferencedCodeAnalyzer.cs b/src/ILLink.RoslynAnalyzer/RequiresUnreferencedCodeAnalyzer.cs
index ba060ccf0..7e4f7e5a2 100644
--- a/src/ILLink.RoslynAnalyzer/RequiresUnreferencedCodeAnalyzer.cs
+++ b/src/ILLink.RoslynAnalyzer/RequiresUnreferencedCodeAnalyzer.cs
@@ -3,11 +3,8 @@
using System;
using System.Collections.Immutable;
-using System.Diagnostics.CodeAnalysis;
using ILLink.Shared;
using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.CSharp;
-using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
namespace ILLink.RoslynAnalyzer
@@ -35,56 +32,6 @@ namespace ILLink.RoslynAnalyzer
operationContext.Operation.Syntax.GetLocation ()));
};
- [SuppressMessage ("MicrosoftCodeAnalysisPerformance", "RS1008",
- Justification = "Storing per-compilation data inside a diagnostic analyzer might cause stale compilations to remain alive." +
- "This action is registered through a compilation start action, so that instances that register this syntax" +
- " node action will not outlive a compilation's lifetime, avoiding the possibility of the locals stored in" +
- " this function to cause for any stale compilations to remain in memory.")]
- static readonly Action<SyntaxNodeAnalysisContext> s_constructorConstraint = syntaxNodeAnalysisContext => {
- var model = syntaxNodeAnalysisContext.SemanticModel;
- if (syntaxNodeAnalysisContext.ContainingSymbol is not ISymbol containingSymbol || containingSymbol.HasAttribute (RequiresUnreferencedCodeAttribute))
- return;
-
- GenericNameSyntax genericNameSyntaxNode = (GenericNameSyntax) syntaxNodeAnalysisContext.Node;
- var typeParams = ImmutableArray<ITypeParameterSymbol>.Empty;
- var typeArgs = ImmutableArray<ITypeSymbol>.Empty;
- switch (model.GetSymbolInfo (genericNameSyntaxNode).Symbol) {
- case INamedTypeSymbol typeSymbol:
- typeParams = typeSymbol.TypeParameters;
- typeArgs = typeSymbol.TypeArguments;
- break;
-
- case IMethodSymbol methodSymbol:
- typeParams = methodSymbol.TypeParameters;
- typeArgs = methodSymbol.TypeArguments;
- break;
-
- default:
- return;
- }
-
- for (int i = 0; i < typeParams.Length; i++) {
- var typeParam = typeParams[i];
- var typeArg = typeArgs[i];
- if (!typeParam.HasConstructorConstraint)
- continue;
-
- var typeArgCtors = ((INamedTypeSymbol) typeArg).InstanceConstructors;
- foreach (var instanceCtor in typeArgCtors) {
- if (instanceCtor.Arity > 0)
- continue;
-
- if (instanceCtor.TryGetAttribute (RequiresUnreferencedCodeAttribute, out var requiresUnreferencedCodeAttribute)) {
- syntaxNodeAnalysisContext.ReportDiagnostic (Diagnostic.Create (s_requiresUnreferencedCodeRule,
- syntaxNodeAnalysisContext.Node.GetLocation (),
- containingSymbol.GetDisplayName (),
- (string) requiresUnreferencedCodeAttribute.ConstructorArguments[0].Value!,
- GetUrlFromAttribute (requiresUnreferencedCodeAttribute)));
- }
- }
- }
- };
-
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics =>
ImmutableArray.Create (s_dynamicTypeInvocationRule, s_makeGenericMethodRule, s_makeGenericTypeRule, s_requiresUnreferencedCodeRule, s_requiresUnreferencedCodeAttributeMismatch);
@@ -133,9 +80,6 @@ namespace ILLink.RoslynAnalyzer
private protected override ImmutableArray<(Action<OperationAnalysisContext> Action, OperationKind[] OperationKind)> ExtraOperationActions =>
ImmutableArray.Create ((s_dynamicTypeInvocation, new OperationKind[] { OperationKind.DynamicInvocation }));
- private protected override ImmutableArray<(Action<SyntaxNodeAnalysisContext> Action, SyntaxKind[] SyntaxKind)> ExtraSyntaxNodeActions =>
- ImmutableArray.Create ((s_constructorConstraint, new SyntaxKind[] { SyntaxKind.GenericName }));
-
protected override bool VerifyAttributeArguments (AttributeData attribute) =>
attribute.ConstructorArguments.Length >= 1 && attribute.ConstructorArguments[0] is { Type: { SpecialType: SpecialType.System_String } } ctorArg;
diff --git a/src/ILLink.Shared/DiagnosticId.cs b/src/ILLink.Shared/DiagnosticId.cs
index 6720edbc4..8fe4fc2fe 100644
--- a/src/ILLink.Shared/DiagnosticId.cs
+++ b/src/ILLink.Shared/DiagnosticId.cs
@@ -14,7 +14,7 @@
AvoidAssemblyLocationInSingleFile = 3000,
AvoidAssemblyGetFilesInSingleFile = 3001,
RequiresAssemblyFiles = 3002,
- RequiresAssembyFilesAttributeMismatch = 3003
+ RequiresAssemblyFilesAttributeMismatch = 3003
}
public static class DiagnosticIdExtensions
diff --git a/src/ILLink.Shared/SharedStrings.resx b/src/ILLink.Shared/SharedStrings.resx
index 807f96a88..36ce24594 100644
--- a/src/ILLink.Shared/SharedStrings.resx
+++ b/src/ILLink.Shared/SharedStrings.resx
@@ -147,6 +147,12 @@
<data name="RequiresUnreferencedCodeAttributeMismatchTitle" xml:space="preserve">
<value>'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides.</value>
</data>
+ <data name="RequiresAssemblyFilesAttributeMismatchMessage" xml:space="preserve">
+ <value>{0}. 'RequiresAssemblyFilesAttribute' annotations must match across all interface implementations or overrides.</value>
+ </data>
+ <data name="RequiresAssemblyFilesAttributeMismatchTitle" xml:space="preserve">
+ <value>'RequiresAssemblyFilesAttribute' annotations must match across all interface implementations or overrides.</value>
+ </data>
<data name="BaseRequiresMismatchMessage" xml:space="preserve">
<value>Base member '{2}' with '{0}' has a derived member '{1}' without '{0}'</value>
</data>
diff --git a/test/ILLink.RoslynAnalyzer.Tests/LinkerTestCases.cs b/test/ILLink.RoslynAnalyzer.Tests/LinkerTestCases.cs
index fed1cbfe6..bade900f4 100644
--- a/test/ILLink.RoslynAnalyzer.Tests/LinkerTestCases.cs
+++ b/test/ILLink.RoslynAnalyzer.Tests/LinkerTestCases.cs
@@ -16,7 +16,7 @@ namespace ILLink.RoslynAnalyzer.Tests
[MemberData (nameof (TestCaseUtils.GetTestData), parameters: nameof (RequiresCapability))]
public void RequiresCapability (string m)
{
- RunTest (nameof (RequiresCapability), m, UseMSBuildProperties (MSBuildPropertyOptionNames.EnableTrimAnalyzer));
+ RunTest (nameof (RequiresCapability), m, UseMSBuildProperties (MSBuildPropertyOptionNames.EnableTrimAnalyzer, MSBuildPropertyOptionNames.EnableSingleFileAnalyzer));
}
[Theory]
diff --git a/test/ILLink.RoslynAnalyzer.Tests/RequiresAssemblyFilesAnalyzerTests.cs b/test/ILLink.RoslynAnalyzer.Tests/RequiresAssemblyFilesAnalyzerTests.cs
index a4bdc5be5..7e27f2782 100644
--- a/test/ILLink.RoslynAnalyzer.Tests/RequiresAssemblyFilesAnalyzerTests.cs
+++ b/test/ILLink.RoslynAnalyzer.Tests/RequiresAssemblyFilesAnalyzerTests.cs
@@ -78,29 +78,6 @@ class C
}
[Fact]
- public Task SimpleDiagnosticOnMethod ()
- {
- var TestRequiresAssemblyFilesOnMethod = @"
-using System.Diagnostics.CodeAnalysis;
-
-class C
-{
- [RequiresAssemblyFiles]
- void M1()
- {
- }
-
- void M2()
- {
- M1();
- }
-}";
- return VerifyRequiresAssemblyFilesAnalyzer (TestRequiresAssemblyFilesOnMethod,
- // (13,3): warning IL3002: Using member 'C.M1()' which has 'RequiresAssemblyFilesAttribute' can break functionality when embedded in a single-file app.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssemblyFiles).WithSpan (13, 3, 13, 7).WithArguments ("C.M1()", "", ""));
- }
-
- [Fact]
public Task SimpleDiagnosticOnProperty ()
{
var TestRequiresAssemblyFilesOnProperty = @"
@@ -160,29 +137,6 @@ class C
}
[Fact]
- public Task RequiresAssemblyFilesWithMessageAndUrl ()
- {
- var TestRequiresAssemblyFilesWithMessageAndUrl = @"
-using System.Diagnostics.CodeAnalysis;
-
-class C
-{
- [RequiresAssemblyFiles (""Message from attribute"", Url = ""https://helpurl"")]
- void M1()
- {
- }
-
- void M2()
- {
- M1();
- }
-}";
- return VerifyRequiresAssemblyFilesAnalyzer (TestRequiresAssemblyFilesWithMessageAndUrl,
- // (13,3): warning IL3002: Using member 'C.M1()' which has 'RequiresAssemblyFilesAttribute' can break functionality when embedded in a single-file app. Message from attribute. https://helpurl
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssemblyFiles).WithSpan (13, 3, 13, 7).WithArguments ("C.M1()", " Message from attribute.", " https://helpurl"));
- }
-
- [Fact]
public Task RequiresAssemblyFilesWithUrlOnly ()
{
var TestRequiresAssemblyFilesWithMessageAndUrl = @"
@@ -395,53 +349,6 @@ class C
}
[Fact]
- public Task LazyDelegateWithRequiresAssemblyFiles ()
- {
- const string src = @"
-using System;
-using System.Diagnostics.CodeAnalysis;
-class C
-{
- public static Lazy<C> _default = new Lazy<C>(InitC);
- public static C Default => _default.Value;
-
- [RequiresAssemblyFiles]
- public static C InitC() {
- C cObject = new C();
- return cObject;
- }
-}";
-
- return VerifyRequiresAssemblyFilesAnalyzer (src,
- // (6,50): warning IL3002: Using member 'C.InitC()' which has 'RequiresAssemblyFilesAttribute' can break functionality when embedded in a single-file app.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssemblyFiles).WithSpan (6, 50, 6, 55).WithArguments ("C.InitC()", "", ""));
- }
-
- [Fact]
- public Task ActionDelegateWithRequiresAssemblyFiles ()
- {
- const string src = @"
-using System;
-using System.Diagnostics.CodeAnalysis;
-class C
-{
- [RequiresAssemblyFiles]
- public static void M1() { }
- public static void M2()
- {
- Action a = M1;
- Action b = () => M1();
- }
-}";
-
- return VerifyRequiresAssemblyFilesAnalyzer (src,
- // (10,20): warning IL3002: Using member 'C.M1()' which has 'RequiresAssemblyFilesAttribute' can break functionality when embedded in a single-file app.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssemblyFiles).WithSpan (10, 20, 10, 22).WithArguments ("C.M1()", "", ""),
- // (11,26): warning IL3002: Using member 'C.M1()' which has 'RequiresAssemblyFilesAttribute' can break functionality when embedded in a single-file app.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssemblyFiles).WithSpan (11, 26, 11, 30).WithArguments ("C.M1()", "", ""));
- }
-
- [Fact]
public Task RequiresAssemblyFilesDiagnosticFix ()
{
var test = @"
@@ -767,467 +674,5 @@ public class C
},
fixedExpected: Array.Empty<DiagnosticResult> ());
}
-
- [Fact]
- public Task TestStaticCctorRequiresAssemblyFiles ()
- {
- var src = @"
-using System.Diagnostics.CodeAnalysis;
-
-class StaticCtor
-{
- [RequiresAssemblyFiles (""Message for --TestStaticCtor--"")]
- static StaticCtor ()
- {
- }
-
- static void TestStaticCctorRequiresUnreferencedCode ()
- {
- _ = new StaticCtor ();
- }
-}";
- return VerifyRequiresAssemblyFilesAnalyzer (src);
- }
-
- [Fact]
- public Task StaticCtorTriggeredByFieldAccess ()
- {
- var src = @"
-using System.Diagnostics.CodeAnalysis;
-
-class StaticCtorTriggeredByFieldAccess
-{
- public static int field;
-
- [RequiresAssemblyFiles (""Message for --StaticCtorTriggeredByFieldAccess.Cctor--"")]
- static StaticCtorTriggeredByFieldAccess ()
- {
- field = 0;
- }
-}
-class C
-{
- static void TestStaticCtorMarkingIsTriggeredByFieldAccess ()
- {
- var x = StaticCtorTriggeredByFieldAccess.field + 1;
- }
-}";
- return VerifyRequiresAssemblyFilesAnalyzer (src);
- }
-
- [Fact]
- public Task TestStaticCtorTriggeredByMethodCall ()
- {
- var src = @"
-using System.Diagnostics.CodeAnalysis;
-
-class StaticCtorTriggeredByMethodCall
-{
- [RequiresAssemblyFiles (""Message for --StaticCtorTriggeredByMethodCall.Cctor--"")]
- static StaticCtorTriggeredByMethodCall ()
- {
- }
-
- [RequiresAssemblyFiles (""Message for --StaticCtorTriggeredByMethodCall.TriggerStaticCtorMarking--"")]
- public void TriggerStaticCtorMarking ()
- {
- }
-}
-
-class C
-{
- static void TestStaticCtorTriggeredByMethodCall ()
- {
- new StaticCtorTriggeredByMethodCall ().TriggerStaticCtorMarking ();
- }
-}";
- return VerifyRequiresAssemblyFilesAnalyzer (src,
- // (21,3): warning IL3002: Using member 'StaticCtorTriggeredByMethodCall.TriggerStaticCtorMarking()' which has 'RequiresAssemblyFilesAttribute' can break functionality when embedded in a single-file app. Message for --StaticCtorTriggeredByMethodCall.TriggerStaticCtorMarking--.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssemblyFiles).WithSpan (21, 3, 21, 69).WithArguments ("StaticCtorTriggeredByMethodCall.TriggerStaticCtorMarking()", " Message for --StaticCtorTriggeredByMethodCall.TriggerStaticCtorMarking--.", "")
- );
- }
-
- [Fact]
- public Task OverrideHasAttributeButBaseDoesnt ()
- {
- var src = @"
-using System.Diagnostics.CodeAnalysis;
-
-class DerivedClass : BaseClass
-{
- [RequiresAssemblyFiles]
- public override void VirtualMethod ()
- {
- }
-
- private string name;
- public override string VirtualPropertyWithAnnotationInAccesor
- {
- [RequiresAssemblyFiles]
- get { return name; }
- set { name = value; }
- }
-
- [RequiresAssemblyFiles]
- public override string VirtualPropertyWithAnnotationInProperty { get; set; }
-}
-
-class BaseClass
-{
- public virtual void VirtualMethod ()
- {
- }
-
- public virtual string VirtualPropertyWithAnnotationInAccesor { get; set; }
-
- public virtual string VirtualPropertyWithAnnotationInProperty { get; set; }
-}";
- return VerifyRequiresAssemblyFilesAnalyzer (src,
- // (7,23): warning IL3003: Member 'DerivedClass.VirtualMethod()' with 'RequiresAssemblyFilesAttribute' overrides base member 'BaseClass.VirtualMethod()' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (7, 23, 7, 36).WithArguments ("Member 'DerivedClass.VirtualMethod()' with 'RequiresAssemblyFilesAttribute' overrides base member 'BaseClass.VirtualMethod()' without 'RequiresAssemblyFilesAttribute'"),
- // (15,3): warning IL3003: Member 'DerivedClass.VirtualPropertyWithAnnotationInAccesor.get' with 'RequiresAssemblyFilesAttribute' overrides base member 'BaseClass.VirtualPropertyWithAnnotationInAccesor.get' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (15, 3, 15, 6).WithArguments ("Member 'DerivedClass.VirtualPropertyWithAnnotationInAccesor.get' with 'RequiresAssemblyFilesAttribute' overrides base member 'BaseClass.VirtualPropertyWithAnnotationInAccesor.get' without 'RequiresAssemblyFilesAttribute'"),
- // (20,25): warning IL3003: Member 'DerivedClass.VirtualPropertyWithAnnotationInProperty' with 'RequiresAssemblyFilesAttribute' overrides base member 'BaseClass.VirtualPropertyWithAnnotationInProperty' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (20, 25, 20, 64).WithArguments ("Member 'DerivedClass.VirtualPropertyWithAnnotationInProperty' with 'RequiresAssemblyFilesAttribute' overrides base member 'BaseClass.VirtualPropertyWithAnnotationInProperty' without 'RequiresAssemblyFilesAttribute'"));
- }
-
- [Fact]
- public Task VirtualHasAttributeButOverrideDoesnt ()
- {
- var src = @"
-using System.Diagnostics.CodeAnalysis;
-
-class DerivedClass : BaseClass
-{
- public override void VirtualMethod ()
- {
- }
-
- private string name;
- public override string VirtualPropertyWithAnnotationInAccesor
- {
- get { return name; }
- set { name = value; }
- }
-
- public override string VirtualPropertyWithAnnotationInProperty { get; set; }
-}
-
-class BaseClass
-{
- [RequiresAssemblyFiles]
- public virtual void VirtualMethod ()
- {
- }
-
- public virtual string VirtualPropertyWithAnnotationInAccesor {[RequiresAssemblyFiles] get; set; }
-
- [RequiresAssemblyFiles]
- public virtual string VirtualPropertyWithAnnotationInProperty { get; set; }
-}";
- return VerifyRequiresAssemblyFilesAnalyzer (src,
- // (6,23): warning IL3003: Base member 'BaseClass.VirtualMethod()' with 'RequiresAssemblyFilesAttribute' has a derived member 'DerivedClass.VirtualMethod()' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (6, 23, 6, 36).WithArguments ("Base member 'BaseClass.VirtualMethod()' with 'RequiresAssemblyFilesAttribute' has a derived member 'DerivedClass.VirtualMethod()' without 'RequiresAssemblyFilesAttribute'"),
- // (13,3): warning IL3003: Base member 'BaseClass.VirtualPropertyWithAnnotationInAccesor.get' with 'RequiresAssemblyFilesAttribute' has a derived member 'DerivedClass.VirtualPropertyWithAnnotationInAccesor.get' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (13, 3, 13, 6).WithArguments ("Base member 'BaseClass.VirtualPropertyWithAnnotationInAccesor.get' with 'RequiresAssemblyFilesAttribute' has a derived member 'DerivedClass.VirtualPropertyWithAnnotationInAccesor.get' without 'RequiresAssemblyFilesAttribute'"),
- // (17,25): warning IL3003: Base member 'BaseClass.VirtualPropertyWithAnnotationInProperty' with 'RequiresAssemblyFilesAttribute' has a derived member 'DerivedClass.VirtualPropertyWithAnnotationInProperty' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (17, 25, 17, 64).WithArguments ("Base member 'BaseClass.VirtualPropertyWithAnnotationInProperty' with 'RequiresAssemblyFilesAttribute' has a derived member 'DerivedClass.VirtualPropertyWithAnnotationInProperty' without 'RequiresAssemblyFilesAttribute'"));
- }
-
- [Fact]
- public Task ImplementationHasAttributeButInterfaceDoesnt ()
- {
- // Once the interface has the attributes indicated in the warnings we would have warnings for AnotherImplementation.
- // In the meantime AnotherImplementation doesn't generate a warning
- var src = @"
-using System.Diagnostics.CodeAnalysis;
-
-class Implementation : IRAF
-{
- [RequiresAssemblyFiles]
- public void Method () { }
-
- private string name;
- public string StringProperty
- {
- [RequiresAssemblyFiles]
- get { return name; }
- set { name = value; }
- }
-
- private int num;
- [RequiresAssemblyFiles]
- public int NumProperty
- {
- get { return num; }
- set { num = value; }
- }
-}
-
-class AnotherImplementation : IRAF
-{
- public void Method () { }
-
- private string name;
- public string StringProperty
- {
- get { return name; }
- set { name = value; }
- }
-
- private int num;
- public int NumProperty
- {
- get { return num; }
- set { num = value; }
- }
-}
-
-class ExplicitImplementation : IRAF
-{
- [RequiresAssemblyFiles]
- void IRAF.Method() { }
-
- private string name;
- string IRAF.StringProperty
- {
- [RequiresAssemblyFiles]
- get { return name; }
- set { name = value; }
- }
-
- private int num;
- [RequiresAssemblyFiles]
- int IRAF.NumProperty
- {
- get { return num; }
- set { num = value; }
- }
-}
-
-interface IRAF
-{
- void Method();
- string StringProperty { get; set; }
- int NumProperty { get; set; }
-}";
- return VerifyRequiresAssemblyFilesAnalyzer (src,
- // (7,14): warning IL3003: Member 'Implementation.Method()' with 'RequiresAssemblyFilesAttribute' implements interface member 'IRAF.Method()' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (7, 14, 7, 20).WithArguments ("Member 'Implementation.Method()' with 'RequiresAssemblyFilesAttribute' implements interface member 'IRAF.Method()' without 'RequiresAssemblyFilesAttribute'"),
- // (13,3): warning IL3003: Member 'Implementation.StringProperty.get' with 'RequiresAssemblyFilesAttribute' implements interface member 'IRAF.StringProperty.get' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (13, 3, 13, 6).WithArguments ("Member 'Implementation.StringProperty.get' with 'RequiresAssemblyFilesAttribute' implements interface member 'IRAF.StringProperty.get' without 'RequiresAssemblyFilesAttribute'"),
- // (19,13): warning IL3003: Member 'Implementation.NumProperty' with 'RequiresAssemblyFilesAttribute' implements interface member 'IRAF.NumProperty' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (19, 13, 19, 24).WithArguments ("Member 'Implementation.NumProperty' with 'RequiresAssemblyFilesAttribute' implements interface member 'IRAF.NumProperty' without 'RequiresAssemblyFilesAttribute'"),
- // (48,12): warning IL3003: Member 'ExplicitImplementation.IRAF.Method()' with 'RequiresAssemblyFilesAttribute' implements interface member 'IRAF.Method()' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (48, 12, 48, 18).WithArguments ("Member 'ExplicitImplementation.IRAF.Method()' with 'RequiresAssemblyFilesAttribute' implements interface member 'IRAF.Method()' without 'RequiresAssemblyFilesAttribute'"),
- // (54,3): warning IL3003: Member 'ExplicitImplementation.IRAF.StringProperty.get' with 'RequiresAssemblyFilesAttribute' implements interface member 'IRAF.StringProperty.get' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (54, 3, 54, 6).WithArguments ("Member 'ExplicitImplementation.IRAF.StringProperty.get' with 'RequiresAssemblyFilesAttribute' implements interface member 'IRAF.StringProperty.get' without 'RequiresAssemblyFilesAttribute'"),
- // (60,11): warning IL3003: Member 'ExplicitImplementation.IRAF.NumProperty' with 'RequiresAssemblyFilesAttribute' implements interface member 'IRAF.NumProperty' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (60, 11, 60, 22).WithArguments ("Member 'ExplicitImplementation.IRAF.NumProperty' with 'RequiresAssemblyFilesAttribute' implements interface member 'IRAF.NumProperty' without 'RequiresAssemblyFilesAttribute'"));
- }
-
- [Fact]
- public Task InterfaceHasAttributeButImplementationDoesnt ()
- {
- var src = @"
-using System.Diagnostics.CodeAnalysis;
-
-class Implementation : IRAF
-{
- public void Method () { }
-
- private string name;
- public string StringProperty
- {
- get { return name; }
- set { name = value; }
- }
-
- private int num;
- public int NumProperty
- {
- get { return num; }
- set { num = value; }
- }
-}
-
-class AnotherImplementation : IRAF
-{
- public void Method () { }
-
- private string name;
- public string StringProperty
- {
- get { return name; }
- set { name = value; }
- }
-
- private int num;
- public int NumProperty
- {
- get { return num; }
- set { num = value; }
- }
-}
-
-interface IRAF
-{
- [RequiresAssemblyFiles]
- void Method();
- string StringProperty { [RequiresAssemblyFiles] get; set; }
- [RequiresAssemblyFiles]
- int NumProperty { get; set; }
-}";
- return VerifyRequiresAssemblyFilesAnalyzer (src,
- // (6,14): warning IL3003: Interface member 'IRAF.Method()' with 'RequiresAssemblyFilesAttribute' has an implementation member 'Implementation.Method()' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (6, 14, 6, 20).WithArguments ("Interface member 'IRAF.Method()' with 'RequiresAssemblyFilesAttribute' has an implementation member 'Implementation.Method()' without 'RequiresAssemblyFilesAttribute'"),
- // (11,3): warning IL3003: Interface member 'IRAF.StringProperty.get' with 'RequiresAssemblyFilesAttribute' has an implementation member 'Implementation.StringProperty.get' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (11, 3, 11, 6).WithArguments ("Interface member 'IRAF.StringProperty.get' with 'RequiresAssemblyFilesAttribute' has an implementation member 'Implementation.StringProperty.get' without 'RequiresAssemblyFilesAttribute'"),
- // (16,13): warning IL3003: Interface member 'IRAF.NumProperty' with 'RequiresAssemblyFilesAttribute' has an implementation member 'Implementation.NumProperty' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (16, 13, 16, 24).WithArguments ("Interface member 'IRAF.NumProperty' with 'RequiresAssemblyFilesAttribute' has an implementation member 'Implementation.NumProperty' without 'RequiresAssemblyFilesAttribute'"),
- // (25,14): warning IL3003: Interface member 'IRAF.Method()' with 'RequiresAssemblyFilesAttribute' has an implementation member 'AnotherImplementation.Method()' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (25, 14, 25, 20).WithArguments ("Interface member 'IRAF.Method()' with 'RequiresAssemblyFilesAttribute' has an implementation member 'AnotherImplementation.Method()' without 'RequiresAssemblyFilesAttribute'"),
- // (30,3): warning IL3003: Interface member 'IRAF.StringProperty.get' with 'RequiresAssemblyFilesAttribute' has an implementation member 'AnotherImplementation.StringProperty.get' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (30, 3, 30, 6).WithArguments ("Interface member 'IRAF.StringProperty.get' with 'RequiresAssemblyFilesAttribute' has an implementation member 'AnotherImplementation.StringProperty.get' without 'RequiresAssemblyFilesAttribute'"),
- // (35,13): warning IL3003: Interface member 'IRAF.NumProperty' with 'RequiresAssemblyFilesAttribute' has an implementation member 'AnotherImplementation.NumProperty' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (35, 13, 35, 24).WithArguments ("Interface member 'IRAF.NumProperty' with 'RequiresAssemblyFilesAttribute' has an implementation member 'AnotherImplementation.NumProperty' without 'RequiresAssemblyFilesAttribute'"));
- }
-
- [Fact]
- public async Task MissingRAFAttributeOnSource ()
- {
- var references = @"
-using System.Diagnostics.CodeAnalysis;
-
-public interface IRAF
-{
- [RequiresAssemblyFiles]
- void Method();
- string StringProperty { [RequiresAssemblyFiles] get; set; }
- [RequiresAssemblyFiles]
- int NumProperty { get; set; }
-}";
-
- var src = @"
-class Implementation : IRAF
-{
- public void Method () { }
-
- private string name;
- public string StringProperty
- {
- get { return name; }
- set { name = value; }
- }
-
- private int num;
- public int NumProperty
- {
- get { return num; }
- set { num = value; }
- }
-}
-
-class AnotherImplementation : IRAF
-{
- public void Method () { }
-
- private string name;
- public string StringProperty
- {
- get { return name; }
- set { name = value; }
- }
-
- private int num;
- public int NumProperty
- {
- get { return num; }
- set { num = value; }
- }
-}
-";
- var compilation = (await TestCaseCompilation.GetCompilation (references)).EmitToImageReference ();
-
- await VerifyRequiresAssemblyFilesAnalyzer (src, additionalReferences: new[] { compilation },
- // (4,14): warning IL3003: Interface member 'IRAF.Method()' with 'RequiresAssemblyFilesAttribute' has an implementation member 'Implementation.Method()' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (4, 14, 4, 20).WithArguments ("Interface member 'IRAF.Method()' with 'RequiresAssemblyFilesAttribute' has an implementation member 'Implementation.Method()' without 'RequiresAssemblyFilesAttribute'"),
- // (9,3): warning IL3003: Interface member 'IRAF.StringProperty.get' with 'RequiresAssemblyFilesAttribute' has an implementation member 'Implementation.StringProperty.get' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (9, 3, 9, 6).WithArguments ("Interface member 'IRAF.StringProperty.get' with 'RequiresAssemblyFilesAttribute' has an implementation member 'Implementation.StringProperty.get' without 'RequiresAssemblyFilesAttribute'"),
- // (14,13): warning IL3003: Interface member 'IRAF.NumProperty' with 'RequiresAssemblyFilesAttribute' has an implementation member 'Implementation.NumProperty' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (14, 13, 14, 24).WithArguments ("Interface member 'IRAF.NumProperty' with 'RequiresAssemblyFilesAttribute' has an implementation member 'Implementation.NumProperty' without 'RequiresAssemblyFilesAttribute'"),
- // (23,14): warning IL3003: Interface member 'IRAF.Method()' with 'RequiresAssemblyFilesAttribute' has an implementation member 'AnotherImplementation.Method()' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (23, 14, 23, 20).WithArguments ("Interface member 'IRAF.Method()' with 'RequiresAssemblyFilesAttribute' has an implementation member 'AnotherImplementation.Method()' without 'RequiresAssemblyFilesAttribute'"),
- // (28,3): warning IL3003: Interface member 'IRAF.StringProperty.get' with 'RequiresAssemblyFilesAttribute' has an implementation member 'AnotherImplementation.StringProperty.get' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (28, 3, 28, 6).WithArguments ("Interface member 'IRAF.StringProperty.get' with 'RequiresAssemblyFilesAttribute' has an implementation member 'AnotherImplementation.StringProperty.get' without 'RequiresAssemblyFilesAttribute'"),
- // (33,13): warning IL3003: Interface member 'IRAF.NumProperty' with 'RequiresAssemblyFilesAttribute' has an implementation member 'AnotherImplementation.NumProperty' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (33, 13, 33, 24).WithArguments ("Interface member 'IRAF.NumProperty' with 'RequiresAssemblyFilesAttribute' has an implementation member 'AnotherImplementation.NumProperty' without 'RequiresAssemblyFilesAttribute'"));
- }
-
- [Fact]
- public async Task MissingRAFAttributeOnReference ()
- {
- var references = @"
-public interface IRAF
-{
- void Method();
- string StringProperty { get; set; }
- int NumProperty { get; set; }
-}";
-
- var src = @"
-using System.Diagnostics.CodeAnalysis;
-
-class Implementation : IRAF
-{
- [RequiresAssemblyFiles]
- public void Method () { }
-
- private string name;
- public string StringProperty
- {
- [RequiresAssemblyFiles]
- get { return name; }
- set { name = value; }
- }
-
- private int num;
- [RequiresAssemblyFiles]
- public int NumProperty
- {
- get { return num; }
- set { num = value; }
- }
-}
-
-class AnotherImplementation : IRAF
-{
- public void Method () { }
-
- private string name;
- public string StringProperty
- {
- get { return name; }
- set { name = value; }
- }
-
- private int num;
- public int NumProperty
- {
- get { return num; }
- set { num = value; }
- }
-}
-";
- var compilation = (await TestCaseCompilation.GetCompilation (references)).EmitToImageReference ();
-
- await VerifyRequiresAssemblyFilesAnalyzer (src, additionalReferences: new[] { compilation },
- // (7,14): warning IL3003: Member 'Implementation.Method()' with 'RequiresAssemblyFilesAttribute' implements interface member 'IRAF.Method()' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (7, 14, 7, 20).WithArguments ("Member 'Implementation.Method()' with 'RequiresAssemblyFilesAttribute' implements interface member 'IRAF.Method()' without 'RequiresAssemblyFilesAttribute'"),
- // (13,3): warning IL3003: Member 'Implementation.StringProperty.get' with 'RequiresAssemblyFilesAttribute' implements interface member 'IRAF.StringProperty.get' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (13, 3, 13, 6).WithArguments ("Member 'Implementation.StringProperty.get' with 'RequiresAssemblyFilesAttribute' implements interface member 'IRAF.StringProperty.get' without 'RequiresAssemblyFilesAttribute'"),
- // (19,13): warning IL3003: Member 'Implementation.NumProperty' with 'RequiresAssemblyFilesAttribute' implements interface member 'IRAF.NumProperty' without 'RequiresAssemblyFilesAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresAssembyFilesAttributeMismatch).WithSpan (19, 13, 19, 24).WithArguments ("Member 'Implementation.NumProperty' with 'RequiresAssemblyFilesAttribute' implements interface member 'IRAF.NumProperty' without 'RequiresAssemblyFilesAttribute'"));
- }
}
}
diff --git a/test/ILLink.RoslynAnalyzer.Tests/RequiresUnreferencedCodeAnalyzerTests.cs b/test/ILLink.RoslynAnalyzer.Tests/RequiresUnreferencedCodeAnalyzerTests.cs
index 9cb7d8995..b54b65f8e 100644
--- a/test/ILLink.RoslynAnalyzer.Tests/RequiresUnreferencedCodeAnalyzerTests.cs
+++ b/test/ILLink.RoslynAnalyzer.Tests/RequiresUnreferencedCodeAnalyzerTests.cs
@@ -54,22 +54,7 @@ build_property.{MSBuildPropertyOptionNames.EnableTrimAnalyzer} = true")));
return test.RunAsync ();
}
- [Fact]
- public Task SimpleDiagnostic ()
- {
- var TestRequiresWithMessageOnlyOnMethod = @"
-using System.Diagnostics.CodeAnalysis;
-class C
-{
- [RequiresUnreferencedCodeAttribute(""message"")]
- int M1() => 0;
- int M2() => M1();
-}";
- return VerifyRequiresUnreferencedCodeAnalyzer (TestRequiresWithMessageOnlyOnMethod,
- // (8,17): warning IL2026: Using member 'C.M1()' which has `RequiresUnreferencedCodeAttribute` can break functionality when trimming application code. message.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCode).WithSpan (8, 17, 8, 21).WithArguments ("C.M1()", " message.", ""));
- }
[Fact]
public async Task SimpleDiagnosticFix ()
@@ -322,541 +307,6 @@ public class C
}
[Fact]
- public Task TestRequiresWithMessageAndUrlOnMethod ()
- {
- var MessageAndUrlOnMethod = @"
-using System.Diagnostics.CodeAnalysis;
-
-class C
-{
- static void TestRequiresWithMessageAndUrlOnMethod ()
- {
- RequiresWithMessageAndUrl ();
- }
- [RequiresUnreferencedCode (""Message for --RequiresWithMessageAndUrl--"", Url = ""https://helpurl"")]
- static void RequiresWithMessageAndUrl ()
- {
- }
-}";
- return VerifyRequiresUnreferencedCodeAnalyzer (MessageAndUrlOnMethod,
- // (8,3): warning IL2026: Using member 'C.RequiresWithMessageAndUrl()' which has `RequiresUnreferencedCodeAttribute` can break functionality when trimming application code. Message for --RequiresWithMessageAndUrl--. https://helpurl
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCode).WithSpan (8, 3, 8, 31).WithArguments ("C.RequiresWithMessageAndUrl()", " Message for --RequiresWithMessageAndUrl--.", " https://helpurl")
- );
- }
-
- [Fact]
- public Task TestTrailingPeriodsOnWarningMessageAreNotDupplicated ()
- {
- var source = @"
-using System.Diagnostics.CodeAnalysis;
-
-class C
-{
- [RequiresUnreferencedCode (""Warning message"")]
- static void MessageWithoutTrailingPeriod ()
- {
- }
-
- [RequiresUnreferencedCode (""Warning message."")]
- static void MessageWithTrailingPeriod ()
- {
- }
-
- static void Test ()
- {
- MessageWithoutTrailingPeriod ();
- MessageWithTrailingPeriod ();
- }
-}";
-
- return VerifyRequiresUnreferencedCodeAnalyzer (source,
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCode).WithSpan (18, 3, 18, 34).WithArguments ("C.MessageWithoutTrailingPeriod()", " Warning message.", string.Empty),
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCode).WithSpan (19, 3, 19, 31).WithArguments ("C.MessageWithTrailingPeriod()", " Warning message.", string.Empty));
- }
-
- [Fact]
- public Task TestRequiresOnPropertyGetter ()
- {
- var PropertyRequires = @"
-using System.Diagnostics.CodeAnalysis;
-
-class C
-{
- static void TestRequiresOnPropertyGetter ()
- {
- _ = PropertyRequires;
- }
-
- static int PropertyRequires {
- [RequiresUnreferencedCode (""Message for --getter PropertyRequires--"")]
- get { return 42; }
- }
-}";
- return VerifyRequiresUnreferencedCodeAnalyzer (PropertyRequires,
- // (8,7): warning IL2026: Using member 'C.PropertyRequires.get' which has `RequiresUnreferencedCodeAttribute` can break functionality when trimming application code. Message for --getter PropertyRequires--.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCode).WithSpan (8, 7, 8, 23).WithArguments ("C.PropertyRequires.get", " Message for --getter PropertyRequires--.", "")
- );
- }
-
- [Fact]
- public Task TestRequiresOnPropertySetter ()
- {
- var PropertyRequires = @"
-using System.Diagnostics.CodeAnalysis;
-
-class C
-{
- static void TestRequiresOnPropertySetter ()
- {
- PropertyRequires = 0;
- }
-
- static int PropertyRequires {
- [RequiresUnreferencedCode (""Message for --setter PropertyRequires--"")]
- set { }
- }
-}";
- return VerifyRequiresUnreferencedCodeAnalyzer (PropertyRequires,
- // (8,3): warning IL2026: Using member 'C.PropertyRequires.set' which has `RequiresUnreferencedCodeAttribute` can break functionality when trimming application code. Message for --setter PropertyRequires--.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCode).WithSpan (8, 3, 8, 19).WithArguments ("C.PropertyRequires.set", " Message for --setter PropertyRequires--.", "")
- );
- }
-
- [Fact]
- public Task TestStaticCctorRequiresUnreferencedCode ()
- {
- var src = @"
-using System.Diagnostics.CodeAnalysis;
-
-class StaticCtor
-{
- [RequiresUnreferencedCode (""Message for --TestStaticCtor--"")]
- static StaticCtor ()
- {
- }
-
- static void TestStaticCctorRequiresUnreferencedCode ()
- {
- _ = new StaticCtor ();
- }
-}";
- return VerifyRequiresUnreferencedCodeAnalyzer (src);
- }
-
- [Fact]
- public Task StaticCtorTriggeredByFieldAccess ()
- {
- var src = @"
-using System.Diagnostics.CodeAnalysis;
-
-class StaticCtorTriggeredByFieldAccess
-{
- public static int field;
-
- [RequiresUnreferencedCode (""Message for --StaticCtorTriggeredByFieldAccess.Cctor--"")]
- static StaticCtorTriggeredByFieldAccess ()
- {
- field = 0;
- }
-}
-class C
-{
- static void TestStaticCtorMarkingIsTriggeredByFieldAccess ()
- {
- var x = StaticCtorTriggeredByFieldAccess.field + 1;
- }
-}";
- return VerifyRequiresUnreferencedCodeAnalyzer (src);
- }
-
- [Fact]
- public Task TestStaticCtorTriggeredByMethodCall ()
- {
- var src = @"
-using System.Diagnostics.CodeAnalysis;
-
-class StaticCtorTriggeredByMethodCall
-{
- [RequiresUnreferencedCode (""Message for --StaticCtorTriggeredByMethodCall.Cctor--"")]
- static StaticCtorTriggeredByMethodCall ()
- {
- }
-
- [RequiresUnreferencedCode (""Message for --StaticCtorTriggeredByMethodCall.TriggerStaticCtorMarking--"")]
- public void TriggerStaticCtorMarking ()
- {
- }
-}
-
-class C
-{
- static void TestStaticCtorTriggeredByMethodCall ()
- {
- new StaticCtorTriggeredByMethodCall ().TriggerStaticCtorMarking ();
- }
-}";
- return VerifyRequiresUnreferencedCodeAnalyzer (src,
- // (21,3): warning IL2026: Using member 'StaticCtorTriggeredByMethodCall.TriggerStaticCtorMarking()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Message for --StaticCtorTriggeredByMethodCall.TriggerStaticCtorMarking--.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCode).WithSpan (21, 3, 21, 69).WithArguments ("StaticCtorTriggeredByMethodCall.TriggerStaticCtorMarking()", " Message for --StaticCtorTriggeredByMethodCall.TriggerStaticCtorMarking--.", "")
- );
- }
-
- [Fact]
- public Task TypeIsBeforeFieldInit ()
- {
- var TypeIsBeforeFieldInit = @"
-using System.Diagnostics.CodeAnalysis;
-
-class C
-{
- class TypeIsBeforeFieldInit
- {
- public static int field = AnnotatedMethod ();
-
- [RequiresUnreferencedCode (""Message from --TypeIsBeforeFieldInit.AnnotatedMethod--"")]
- public static int AnnotatedMethod () => 42;
- }
-
- static void TestTypeIsBeforeFieldInit ()
- {
- var x = TypeIsBeforeFieldInit.field + 42;
- }
-}";
- return VerifyRequiresUnreferencedCodeAnalyzer (TypeIsBeforeFieldInit,
- // (8,29): warning IL2026: Using member 'C.TypeIsBeforeFieldInit.AnnotatedMethod()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Message from --TypeIsBeforeFieldInit.AnnotatedMethod--.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCode).WithSpan (8, 29, 8, 47).WithArguments ("C.TypeIsBeforeFieldInit.AnnotatedMethod()", " Message from --TypeIsBeforeFieldInit.AnnotatedMethod--.", "")
- );
- }
-
- [Fact]
- public Task LazyDelegateWithRequiresUnreferencedCode ()
- {
- const string src = @"
-using System;
-using System.Diagnostics.CodeAnalysis;
-class C
-{
- public static Lazy<C> _default = new Lazy<C>(InitC);
- public static C Default => _default.Value;
-
- [RequiresUnreferencedCode (""Message from --C.InitC--"")]
- public static C InitC() {
- C cObject = new C();
- return cObject;
- }
-}";
-
- return VerifyRequiresUnreferencedCodeAnalyzer (src,
- // (6,50): warning IL2026: Using member 'C.InitC()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Message from --C.InitC--.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCode).WithSpan (6, 50, 6, 55).WithArguments ("C.InitC()", " Message from --C.InitC--.", ""));
- }
-
- [Fact]
- public Task ActionDelegateWithRequiresAssemblyFiles ()
- {
- const string src = @"
-using System;
-using System.Diagnostics.CodeAnalysis;
-class C
-{
- [RequiresUnreferencedCode (""Message from --C.M1--"")]
- public static void M1() { }
- public static void M2()
- {
- Action a = M1;
- Action b = () => M1();
- }
-}";
-
- return VerifyRequiresUnreferencedCodeAnalyzer (src,
- // (10,20): warning IL2026: Using member 'C.M1()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Message from --C.M1--.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCode).WithSpan (10, 20, 10, 22).WithArguments ("C.M1()", " Message from --C.M1--.", ""),
- // (11,26): warning IL2026: Using member 'C.M1()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Message from --C.M1--.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCode).WithSpan (11, 26, 11, 30).WithArguments ("C.M1()", " Message from --C.M1--.", ""));
- }
-
- [Fact]
- public Task OverrideHasAttributeButBaseDoesnt ()
- {
- var src = @"
-using System.Diagnostics.CodeAnalysis;
-
-class DerivedClass : BaseClass
-{
- [RequiresUnreferencedCode(""Message"")]
- public override void VirtualMethod ()
- {
- }
-
- private string name;
- public override string VirtualProperty
- {
- [RequiresUnreferencedCode(""Message"")]
- get { return name; }
- set { name = value; }
- }
-}
-
-class BaseClass
-{
- public virtual void VirtualMethod ()
- {
- }
-
- public virtual string VirtualProperty { get; set; }
-}";
- return VerifyRequiresUnreferencedCodeAnalyzer (src,
- // (7,23): warning IL2046: Member 'DerivedClass.VirtualMethod()' with 'RequiresUnreferencedCodeAttribute' overrides base member 'BaseClass.VirtualMethod()' without 'RequiresUnreferencedCodeAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCodeAttributeMismatch).WithSpan (7, 23, 7, 36).WithArguments ("Member 'DerivedClass.VirtualMethod()' with 'RequiresUnreferencedCodeAttribute' overrides base member 'BaseClass.VirtualMethod()' without 'RequiresUnreferencedCodeAttribute'"),
- // (15,3): warning IL2046: Member 'DerivedClass.VirtualProperty.get' with 'RequiresUnreferencedCodeAttribute' overrides base member 'BaseClass.VirtualProperty.get' without 'RequiresUnreferencedCodeAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCodeAttributeMismatch).WithSpan (15, 3, 15, 6).WithArguments ("Member 'DerivedClass.VirtualProperty.get' with 'RequiresUnreferencedCodeAttribute' overrides base member 'BaseClass.VirtualProperty.get' without 'RequiresUnreferencedCodeAttribute'"));
- }
-
- [Fact]
- public Task VirtualHasAttributeButOverrideDoesnt ()
- {
- var src = @"
-using System.Diagnostics.CodeAnalysis;
-
-class DerivedClass : BaseClass
-{
- public override void VirtualMethod ()
- {
- }
-
- private string name;
- public override string VirtualProperty
- {
- get { return name; }
- set { name = value; }
- }
-}
-
-class BaseClass
-{
- [RequiresUnreferencedCode(""Message"")]
- public virtual void VirtualMethod ()
- {
- }
-
- public virtual string VirtualProperty {[RequiresUnreferencedCode(""Message"")] get; set; }
-}";
- return VerifyRequiresUnreferencedCodeAnalyzer (src,
- // (13,3): warning IL2046: Base member 'BaseClass.VirtualProperty.get' with 'RequiresUnreferencedCodeAttribute' has a derived member 'DerivedClass.VirtualProperty.get' without 'RequiresUnreferencedCodeAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCodeAttributeMismatch).WithSpan (13, 3, 13, 6).WithArguments ("Base member 'BaseClass.VirtualProperty.get' with 'RequiresUnreferencedCodeAttribute' has a derived member 'DerivedClass.VirtualProperty.get' without 'RequiresUnreferencedCodeAttribute'"),
- // (6,23): warning IL2046: Base member 'BaseClass.VirtualMethod()' with 'RequiresUnreferencedCodeAttribute' has a derived member 'DerivedClass.VirtualMethod()' without 'RequiresUnreferencedCodeAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCodeAttributeMismatch).WithSpan (6, 23, 6, 36).WithArguments ("Base member 'BaseClass.VirtualMethod()' with 'RequiresUnreferencedCodeAttribute' has a derived member 'DerivedClass.VirtualMethod()' without 'RequiresUnreferencedCodeAttribute'"));
- }
-
- [Fact]
- public Task ImplementationHasAttributeButInterfaceDoesnt ()
- {
- var src = @"
-using System.Diagnostics.CodeAnalysis;
-
-class Implementation : IRUC
-{
- [RequiresUnreferencedCode(""Message"")]
- public void RUC () { }
-
- private string name;
- public string Property
- {
- [RequiresUnreferencedCode(""Message"")]
- get { return name; }
- set { name = value; }
- }
-}
-
-class AnotherImplementation : IRUC
-{
- public void RUC () { }
-
- private string name;
- public string Property
- {
- get { return name; }
- set { name = value; }
- }
-}
-
-class ExplicitImplementation : IRUC
-{
- [RequiresUnreferencedCode(""Message"")]
- void IRUC.RUC() { }
-
- private string name;
- string IRUC.Property
- {
- [RequiresUnreferencedCode(""Message"")]
- get { return name; }
- set { name = value; }
- }
-}
-
-interface IRUC
-{
- void RUC();
- string Property { get; set; }
-}";
- return VerifyRequiresUnreferencedCodeAnalyzer (src,
- // (7,14): warning IL2046: Member 'Implementation.RUC()' with 'RequiresUnreferencedCodeAttribute' implements interface member 'IRUC.RUC()' without 'RequiresUnreferencedCodeAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCodeAttributeMismatch).WithSpan (7, 14, 7, 17).WithArguments ("Member 'Implementation.RUC()' with 'RequiresUnreferencedCodeAttribute' implements interface member 'IRUC.RUC()' without 'RequiresUnreferencedCodeAttribute'"),
- // (13,3): warning IL2046: Member 'Implementation.Property.get' with 'RequiresUnreferencedCodeAttribute' implements interface member 'IRUC.Property.get' without 'RequiresUnreferencedCodeAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCodeAttributeMismatch).WithSpan (13, 3, 13, 6).WithArguments ("Member 'Implementation.Property.get' with 'RequiresUnreferencedCodeAttribute' implements interface member 'IRUC.Property.get' without 'RequiresUnreferencedCodeAttribute'"),
- // (33,12): warning IL2046: Member 'ExplicitImplementation.IRUC.RUC()' with 'RequiresUnreferencedCodeAttribute' implements interface member 'IRUC.RUC()' without 'RequiresUnreferencedCodeAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCodeAttributeMismatch).WithSpan (33, 12, 33, 15).WithArguments ("Member 'ExplicitImplementation.IRUC.RUC()' with 'RequiresUnreferencedCodeAttribute' implements interface member 'IRUC.RUC()' without 'RequiresUnreferencedCodeAttribute'"),
- // (39,3): warning IL2046: Member 'ExplicitImplementation.IRUC.Property.get' with 'RequiresUnreferencedCodeAttribute' implements interface member 'IRUC.Property.get' without 'RequiresUnreferencedCodeAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCodeAttributeMismatch).WithSpan (39, 3, 39, 6).WithArguments ("Member 'ExplicitImplementation.IRUC.Property.get' with 'RequiresUnreferencedCodeAttribute' implements interface member 'IRUC.Property.get' without 'RequiresUnreferencedCodeAttribute'"));
- }
-
- [Fact]
- public Task InterfaceHasAttributeButImplementationDoesnt ()
- {
- var src = @"
-using System.Diagnostics.CodeAnalysis;
-
-class Implementation : IRUC
-{
- public void RUC () { }
-
- private string name;
- public string Property
- {
- get { return name; }
- set { name = value; }
- }
-}
-
-class AnotherImplementation : IRUC
-{
- public void RUC () { }
-
- private string name;
- public string Property
- {
- get { return name; }
- set { name = value; }
- }
-}
-
-interface IRUC
-{
- [RequiresUnreferencedCode(""Message"")]
- void RUC();
- string Property {[RequiresUnreferencedCode(""Message"")] get; set; }
-}";
- return VerifyRequiresUnreferencedCodeAnalyzer (src,
- // (6,14): warning IL2046: Interface member 'IRUC.RUC()' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'Implementation.RUC()' without 'RequiresUnreferencedCodeAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCodeAttributeMismatch).WithSpan (6, 14, 6, 17).WithArguments ("Interface member 'IRUC.RUC()' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'Implementation.RUC()' without 'RequiresUnreferencedCodeAttribute'"),
- // (11,3): warning IL2046: Interface member 'IRUC.Property.get' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'Implementation.Property.get' without 'RequiresUnreferencedCodeAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCodeAttributeMismatch).WithSpan (11, 3, 11, 6).WithArguments ("Interface member 'IRUC.Property.get' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'Implementation.Property.get' without 'RequiresUnreferencedCodeAttribute'"),
- // (18,14): warning IL2046: Interface member 'IRUC.RUC()' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'AnotherImplementation.RUC()' without 'RequiresUnreferencedCodeAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCodeAttributeMismatch).WithSpan (18, 14, 18, 17).WithArguments ("Interface member 'IRUC.RUC()' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'AnotherImplementation.RUC()' without 'RequiresUnreferencedCodeAttribute'"),
- // (23,3): warning IL2046: Interface member 'IRUC.Property.get' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'AnotherImplementation.Property.get' without 'RequiresUnreferencedCodeAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCodeAttributeMismatch).WithSpan (23, 3, 23, 6).WithArguments ("Interface member 'IRUC.Property.get' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'AnotherImplementation.Property.get' without 'RequiresUnreferencedCodeAttribute'"));
- }
-
- [Fact]
- public async Task MissingRAFAttributeOnSource ()
- {
- var references = @"
-using System.Diagnostics.CodeAnalysis;
-
-public interface IRAF
-{
- [RequiresUnreferencedCode (""Message"")]
- void Method();
- string StringProperty { [RequiresUnreferencedCode (""Message"")] get; set; }
-}";
-
- var src = @"
-class Implementation : IRAF
-{
- public void Method () { }
-
- private string name;
- public string StringProperty
- {
- get { return name; }
- set { name = value; }
- }
-}
-
-class AnotherImplementation : IRAF
-{
- public void Method () { }
-
- private string name;
- public string StringProperty
- {
- get { return name; }
- set { name = value; }
- }
-}
-";
- var compilation = (await TestCaseCompilation.GetCompilation (references)).EmitToImageReference ();
-
- await VerifyRequiresUnreferencedCodeAnalyzer (src, additionalReferences: new[] { compilation },
- // (4,14): warning IL2046: Interface member 'IRAF.Method()' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'Implementation.Method()' without 'RequiresUnreferencedCodeAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCodeAttributeMismatch).WithSpan (4, 14, 4, 20).WithArguments ("Interface member 'IRAF.Method()' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'Implementation.Method()' without 'RequiresUnreferencedCodeAttribute'"),
- // (16,14): warning IL2046: Interface member 'IRAF.Method()' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'AnotherImplementation.Method()' without 'RequiresUnreferencedCodeAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCodeAttributeMismatch).WithSpan (16, 14, 16, 20).WithArguments ("Interface member 'IRAF.Method()' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'AnotherImplementation.Method()' without 'RequiresUnreferencedCodeAttribute'"),
- // (9,3): warning IL2046: Interface member 'IRAF.StringProperty.get' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'Implementation.StringProperty.get' without 'RequiresUnreferencedCodeAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCodeAttributeMismatch).WithSpan (9, 3, 9, 6).WithArguments ("Interface member 'IRAF.StringProperty.get' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'Implementation.StringProperty.get' without 'RequiresUnreferencedCodeAttribute'"),
- // (21,3): warning IL2046: Interface member 'IRAF.StringProperty.get' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'AnotherImplementation.StringProperty.get' without 'RequiresUnreferencedCodeAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCodeAttributeMismatch).WithSpan (21, 3, 21, 6).WithArguments ("Interface member 'IRAF.StringProperty.get' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'AnotherImplementation.StringProperty.get' without 'RequiresUnreferencedCodeAttribute'"));
- }
-
- [Fact]
- public async Task MissingRAFAttributeOnReference ()
- {
- var references = @"
-public interface IRAF
-{
- void Method();
- string StringProperty { get; set; }
-}";
-
- var src = @"
-using System.Diagnostics.CodeAnalysis;
-
-class Implementation : IRAF
-{
- [RequiresUnreferencedCode (""Message"")]
- public void Method () { }
-
- private string name;
- public string StringProperty
- {
- [RequiresUnreferencedCode (""Message"")]
- get { return name; }
- set { name = value; }
- }
-}
-
-class AnotherImplementation : IRAF
-{
- public void Method () { }
-
- private string name;
- public string StringProperty
- {
- get { return name; }
- set { name = value; }
- }
-}
-";
- var compilation = (await TestCaseCompilation.GetCompilation (references)).EmitToImageReference ();
-
- await VerifyRequiresUnreferencedCodeAnalyzer (src, additionalReferences: new[] { compilation },
- // (7,14): warning IL2046: Member 'Implementation.Method()' with 'RequiresUnreferencedCodeAttribute' implements interface member 'IRAF.Method()' without 'RequiresUnreferencedCodeAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCodeAttributeMismatch).WithSpan (7, 14, 7, 20).WithArguments ("Member 'Implementation.Method()' with 'RequiresUnreferencedCodeAttribute' implements interface member 'IRAF.Method()' without 'RequiresUnreferencedCodeAttribute'"),
- // (13,3): warning IL2046: Member 'Implementation.StringProperty.get' with 'RequiresUnreferencedCodeAttribute' implements interface member 'IRAF.StringProperty.get' without 'RequiresUnreferencedCodeAttribute'. Attributes must match across all interface implementations or overrides.
- VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCodeAttributeMismatch).WithSpan (13, 3, 13, 6).WithArguments ("Member 'Implementation.StringProperty.get' with 'RequiresUnreferencedCodeAttribute' implements interface member 'IRAF.StringProperty.get' without 'RequiresUnreferencedCodeAttribute'"));
- }
-
- [Fact]
public Task InvocationOnDynamicType ()
{
var source = @"
diff --git a/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs b/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs
index 995825152..e86ee919f 100644
--- a/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs
+++ b/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs
@@ -172,7 +172,7 @@ namespace ILLink.RoslynAnalyzer.Tests
}
}
- missingDiagnosticMessage = $"Expected to find warning containing:{string.Join (" ", expectedMessages.Select (m => "'" + m + "'"))}" +
+ missingDiagnosticMessage = $"Warning '{expectedWarningCode}'. Expected to find warning containing:{string.Join (" ", expectedMessages.Select (m => "'" + m + "'"))}" +
$", but no such message was found.{ Environment.NewLine}";
return false;
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/LogContainsAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/LogContainsAttribute.cs
index fe054761b..934512ce5 100644
--- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/LogContainsAttribute.cs
+++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/LogContainsAttribute.cs
@@ -14,6 +14,10 @@ namespace Mono.Linker.Tests.Cases.Expectations.Assertions
throw new ArgumentException ("Value cannot be null or empty.", nameof (message));
}
+ /// <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;
}
} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/LogDoesNotContainAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/LogDoesNotContainAttribute.cs
index 599908cfb..2cd8667ed 100644
--- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/LogDoesNotContainAttribute.cs
+++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/LogDoesNotContainAttribute.cs
@@ -13,5 +13,11 @@ namespace Mono.Linker.Tests.Cases.Expectations.Assertions
if (string.IsNullOrEmpty (message))
throw new ArgumentException ("Value cannot be null or empty.", nameof (message));
}
+
+ /// <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;
}
}
diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/Dependencies/ReferenceInterfaces.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/Dependencies/ReferenceInterfaces.cs
new file mode 100644
index 000000000..e30fd271c
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/Dependencies/ReferenceInterfaces.cs
@@ -0,0 +1,44 @@
+// 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.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Mono.Linker.Tests.Cases.RequiresCapability.Dependencies
+{
+ public class ReferenceInterfaces
+ {
+ public interface IBaseWithRequiresInReference
+ {
+ [RequiresUnreferencedCode ("Message")]
+ [RequiresAssemblyFiles ("Message")]
+ public void Method ();
+
+ public string PropertyAnnotationInAccesor {
+ [RequiresUnreferencedCode ("Message")]
+ [RequiresAssemblyFiles ("Message")]
+ get;
+ set;
+ }
+
+ [RequiresAssemblyFiles ("Message")]
+ public string PropertyAnnotationInProperty { get; set; }
+ }
+
+ public interface IBaseWithoutRequiresInReference
+ {
+ public void Method ();
+
+ public string PropertyAnnotationInAccesor {
+ get;
+ set;
+ }
+
+ public string PropertyAnnotationInProperty { get; set; }
+ }
+ }
+} \ No newline at end of file
diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/Dependencies/RequiresInCopyAssembly.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/Dependencies/RequiresInCopyAssembly.cs
index 74cdff268..c121ff4ef 100644
--- a/test/Mono.Linker.Tests.Cases/RequiresCapability/Dependencies/RequiresInCopyAssembly.cs
+++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/Dependencies/RequiresInCopyAssembly.cs
@@ -15,24 +15,29 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability.Dependencies
}
[RequiresUnreferencedCode ("Message for --Method--")]
+ [RequiresAssemblyFiles ("Message for --Method--")]
public void Method ()
{
}
[RequiresUnreferencedCode ("Message for --UncalledMethod--")]
+ [RequiresAssemblyFiles ("Message for --UncalledMethod--")]
public void UncalledMethod ()
{
}
[RequiresUnreferencedCode ("Message for --MethodCalledThroughReflection--")]
+ [RequiresAssemblyFiles ("Message for --MethodCalledThroughReflection--")]
static void MethodCalledThroughReflection ()
{
}
public int UnusedProperty {
[RequiresUnreferencedCode ("Message for --getter UnusedProperty--")]
+ [RequiresAssemblyFiles ("Message for --getter UnusedProperty--")]
get { return 42; }
+ [RequiresAssemblyFiles ("Message for --setter UnusedProperty--")]
[RequiresUnreferencedCode ("Message for --setter UnusedProperty--")]
set { }
}
@@ -40,16 +45,19 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability.Dependencies
class UnusedBaseType
{
[RequiresUnreferencedCode ("Message for --UnusedBaseTypeCctor--")]
+ [RequiresAssemblyFiles ("Message for --UnusedBaseTypeCctor--")]
static UnusedBaseType ()
{
}
[RequiresUnreferencedCode ("Message for --UnusedVirtualMethod1--")]
+ [RequiresAssemblyFiles ("Message for --UnusedVirtualMethod1--")]
public virtual void UnusedVirtualMethod1 ()
{
}
[RequiresUnreferencedCode ("Message for --UnusedVirtualMethod2--")]
+ [RequiresAssemblyFiles ("Message for --UnusedVirtualMethod2--")]
public virtual void UnusedVirtualMethod2 ()
{
}
@@ -58,6 +66,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability.Dependencies
class UnusedDerivedType : UnusedBaseType
{
[RequiresUnreferencedCode ("Message for --UnusedVirtualMethod1--")]
+ [RequiresAssemblyFiles ("Message for --UnusedVirtualMethod1--")]
public override void UnusedVirtualMethod1 ()
{
}
@@ -71,12 +80,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability.Dependencies
interface IUnusedInterface
{
[RequiresUnreferencedCode ("Message for --IUnusedInterface.UnusedMethod--")]
+ [RequiresAssemblyFiles ("Message for --IUnusedInterface.UnusedMethod--")]
public void UnusedMethod ();
}
class UnusedImplementationClass : IUnusedInterface
{
[RequiresUnreferencedCode ("Message for --UnusedImplementationClass.UnusedMethod--")]
+ [RequiresAssemblyFiles ("Message for --UnusedImplementationClass.UnusedMethod--")]
public void UnusedMethod ()
{
}
@@ -85,12 +96,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability.Dependencies
public interface IBaseInterface
{
[RequiresUnreferencedCode ("Message for --IBaseInterface.MethodInBaseInterface--")]
+ [RequiresAssemblyFiles ("Message for --IBaseInterface.MethodInBaseInterface--")]
void MethodInBaseInterface ();
}
public interface IDerivedInterface : IBaseInterface
{
[RequiresUnreferencedCode ("Message for --IDerivedInterface.MethodInDerivedInterface--")]
+ [RequiresAssemblyFiles ("Message for --IDerivedInterface.MethodInDerivedInterface--")]
void MethodInDerivedInterface ();
}
}
diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapability.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapability.cs
index f7155e5fe..22800682e 100644
--- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapability.cs
+++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapability.cs
@@ -19,6 +19,9 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
[SetupLinkerAction ("copy", "lib")]
[SetupCompileBefore ("lib.dll", new[] { "Dependencies/RequiresInCopyAssembly.cs" })]
[KeptAllTypesAndMembersInAssembly ("lib.dll")]
+ [SetupLinkerAction ("copy", "lib2")]
+ [SetupCompileBefore ("lib2.dll", new[] { "Dependencies/ReferenceInterfaces.cs" })]
+ [KeptAllTypesAndMembersInAssembly ("lib2.dll")]
[SetupLinkAttributesFile ("RequiresCapability.attributes.xml")]
[SetupLinkerDescriptorFile ("RequiresCapability.descriptor.xml")]
[SkipKeptItemsValidation]
@@ -82,32 +85,38 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
AccessThroughNewConstraint.TestNewConstraintOnTypeParameter ();
AccessThroughNewConstraint.TestNewConstraintOnTypeParameterOfStaticType ();
AccessThroughLdToken.Test ();
+ AttributeMismatch.Test ();
RequiresOnClass.Test ();
}
[ExpectedWarning ("IL2026", "Message for --RequiresWithMessageOnly--.")]
+ [ExpectedWarning ("IL3002", "Message for --RequiresWithMessageOnly--.", ProducedBy = ProducedBy.Analyzer)]
static void TestRequiresWithMessageOnlyOnMethod ()
{
RequiresWithMessageOnly ();
}
[RequiresUnreferencedCode ("Message for --RequiresWithMessageOnly--")]
+ [RequiresAssemblyFiles ("Message for --RequiresWithMessageOnly--")]
static void RequiresWithMessageOnly ()
{
}
[ExpectedWarning ("IL2026", "Message for --RequiresWithMessageAndUrl--.", "https://helpurl")]
+ [ExpectedWarning ("IL3002", "Message for --RequiresWithMessageAndUrl--.", "https://helpurl", ProducedBy = ProducedBy.Analyzer)]
static void TestRequiresWithMessageAndUrlOnMethod ()
{
RequiresWithMessageAndUrl ();
}
[RequiresUnreferencedCode ("Message for --RequiresWithMessageAndUrl--", Url = "https://helpurl")]
+ [RequiresAssemblyFiles ("Message for --RequiresWithMessageAndUrl--", Url = "https://helpurl")]
static void RequiresWithMessageAndUrl ()
{
}
[ExpectedWarning ("IL2026", "Message for --ConstructorRequires--.")]
+ [ExpectedWarning ("IL3002", "Message for --ConstructorRequires--.", ProducedBy = ProducedBy.Analyzer)]
static void TestRequiresOnConstructor ()
{
new ConstructorRequires ();
@@ -116,6 +125,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class ConstructorRequires
{
[RequiresUnreferencedCode ("Message for --ConstructorRequires--")]
+ [RequiresAssemblyFiles ("Message for --ConstructorRequires--")]
public ConstructorRequires ()
{
}
@@ -123,6 +133,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
[ExpectedWarning ("IL2026", "Message for --getter PropertyRequires--.")]
[ExpectedWarning ("IL2026", "Message for --setter PropertyRequires--.")]
+ [ExpectedWarning ("IL3002", "Message for --getter PropertyRequires--.", ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL3002", "Message for --setter PropertyRequires--.", ProducedBy = ProducedBy.Analyzer)]
static void TestRequiresOnPropertyGetterAndSetter ()
{
_ = PropertyRequires;
@@ -131,9 +143,11 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
static int PropertyRequires {
[RequiresUnreferencedCode ("Message for --getter PropertyRequires--")]
+ [RequiresAssemblyFiles ("Message for --getter PropertyRequires--")]
get { return 42; }
[RequiresUnreferencedCode ("Message for --setter PropertyRequires--")]
+ [RequiresAssemblyFiles ("Message for --setter PropertyRequires--")]
set { }
}
@@ -144,6 +158,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
static Type GetUnknownType () => null;
[RequiresUnreferencedCode ("Message for --MethodWithRequires--")]
+ [RequiresAssemblyFiles ("Message for --MethodWithRequires--")]
static void MethodWithRequires ()
{
}
@@ -152,6 +167,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
static Type _requiresPublicConstructors;
[RequiresUnreferencedCode ("")]
+ [RequiresAssemblyFiles ("")]
static void TestMethodWithRequires ()
{
// Normally this would warn, but with the attribute on this method it should be auto-suppressed
@@ -159,24 +175,28 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("")]
+ [RequiresAssemblyFiles ("")]
static void TestParameter ()
{
_unknownType.RequiresPublicMethods ();
}
[RequiresUnreferencedCode ("")]
+ [RequiresAssemblyFiles ("")]
static void TestReturnValue ()
{
GetUnknownType ().RequiresPublicEvents ();
}
[RequiresUnreferencedCode ("")]
+ [RequiresAssemblyFiles ("")]
static void TestField ()
{
_requiresPublicConstructors = _unknownType;
}
[UnconditionalSuppressMessage ("Trimming", "IL2026")]
+ [UnconditionalSuppressMessage ("SingleFile", "IL3002")]
public static void Test ()
{
TestMethodWithRequires ();
@@ -196,36 +216,42 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class GenericTypeRequiresPublicFields<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] T> { }
[RequiresUnreferencedCode ("")]
+ [RequiresAssemblyFiles ("")]
static void TestGenericMethod ()
{
GenericMethodRequiresPublicMethods<TUnknown> ();
}
[RequiresUnreferencedCode ("")]
+ [RequiresAssemblyFiles ("")]
static void TestGenericMethodMismatch ()
{
GenericMethodRequiresPublicMethods<TPublicProperties> ();
}
[RequiresUnreferencedCode ("")]
+ [RequiresAssemblyFiles ("")]
static void TestGenericType ()
{
new GenericTypeRequiresPublicFields<TUnknown> ();
}
[RequiresUnreferencedCode ("")]
+ [RequiresAssemblyFiles ("")]
static void TestMakeGenericTypeWithStaticTypes ()
{
typeof (GenericTypeRequiresPublicFields<>).MakeGenericType (typeof (TUnknown));
}
[RequiresUnreferencedCode ("")]
+ [RequiresAssemblyFiles ("")]
static void TestMakeGenericTypeWithDynamicTypes ()
{
typeof (GenericTypeRequiresPublicFields<>).MakeGenericType (_unknownType);
}
[RequiresUnreferencedCode ("")]
+ [RequiresAssemblyFiles ("")]
static void TestMakeGenericMethod ()
{
typeof (SuppressGenericParameters<TUnknown, TPublicProperties>)
@@ -234,6 +260,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[UnconditionalSuppressMessage ("Trimming", "IL2026")]
+ [UnconditionalSuppressMessage ("SingleFile", "IL3002")]
public static void Test ()
{
TestGenericMethod ();
@@ -292,6 +319,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class BaseType
{
[RequiresUnreferencedCode ("Message for --BaseType.VirtualMethodRequires--")]
+ [RequiresAssemblyFiles ("Message for --BaseType.VirtualMethodRequires--")]
public virtual void VirtualMethodRequires ()
{
}
@@ -300,12 +328,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class TypeWhichOverridesMethod : BaseType
{
[RequiresUnreferencedCode ("Message for --TypeWhichOverridesMethod.VirtualMethodRequires--")]
+ [RequiresAssemblyFiles ("Message for --TypeWhichOverridesMethod.VirtualMethodRequires--")]
public override void VirtualMethodRequires ()
{
}
}
[ExpectedWarning ("IL2026", "--BaseType.VirtualMethodRequires--")]
+ [ExpectedWarning ("IL3002", "--BaseType.VirtualMethodRequires--", ProducedBy = ProducedBy.Analyzer)]
static void TestBaseTypeVirtualMethodRequires ()
{
var tmp = new BaseType ();
@@ -314,6 +344,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
[LogDoesNotContain ("TypeWhichOverridesMethod.VirtualMethodRequires")]
[ExpectedWarning ("IL2026", "--BaseType.VirtualMethodRequires--")]
+ [ExpectedWarning ("IL3002", "--BaseType.VirtualMethodRequires--", ProducedBy = ProducedBy.Analyzer)]
static void TestTypeWhichOverridesMethodVirtualMethodRequires ()
{
var tmp = new TypeWhichOverridesMethod ();
@@ -322,6 +353,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
[LogDoesNotContain ("TypeWhichOverridesMethod.VirtualMethodRequires")]
[ExpectedWarning ("IL2026", "--BaseType.VirtualMethodRequires--")]
+ [ExpectedWarning ("IL3002", "--BaseType.VirtualMethodRequires--", ProducedBy = ProducedBy.Analyzer)]
static void TestTypeWhichOverridesMethodVirtualMethodRequiresOnBase ()
{
BaseType tmp = new TypeWhichOverridesMethod ();
@@ -330,19 +362,25 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class PropertyBaseType
{
- public virtual int VirtualPropertyRequires { [RequiresUnreferencedCode ("Message for --PropertyBaseType.VirtualPropertyRequires--")] get; }
+ public virtual int VirtualPropertyRequires {
+ [RequiresUnreferencedCode ("Message for --PropertyBaseType.VirtualPropertyRequires--")]
+ [RequiresAssemblyFiles ("Message for --PropertyBaseType.VirtualPropertyRequires--")]
+ get;
+ }
}
class TypeWhichOverridesProperty : PropertyBaseType
{
public override int VirtualPropertyRequires {
[RequiresUnreferencedCode ("Message for --TypeWhichOverridesProperty.VirtualPropertyRequires--")]
+ [RequiresAssemblyFiles ("Message for --TypeWhichOverridesProperty.VirtualPropertyRequires--")]
get { return 1; }
}
}
[LogDoesNotContain ("TypeWhichOverridesProperty.VirtualPropertyRequires")]
[ExpectedWarning ("IL2026", "--PropertyBaseType.VirtualPropertyRequires--")]
+ [ExpectedWarning ("IL3002", "--PropertyBaseType.VirtualPropertyRequires--", ProducedBy = ProducedBy.Analyzer)]
static void TestTypeWhichOverridesVirtualPropertyRequires ()
{
var tmp = new TypeWhichOverridesProperty ();
@@ -382,6 +420,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
struct StaticCCtorForFieldAccess
{
+ // TODO: Analyzer still allows RUC/RAF on static constructor with no warning
+ // https://github.com/dotnet/linker/issues/2347
[ExpectedWarning ("IL2116", "StaticCCtorForFieldAccess..cctor()", ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("Message for --StaticCCtorForFieldAccess.cctor--")]
static StaticCCtorForFieldAccess () { }
@@ -397,9 +437,11 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class TypeIsBeforeFieldInit
{
[ExpectedWarning ("IL2026", "Message from --TypeIsBeforeFieldInit.AnnotatedMethod--", ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL3002", "Message from --TypeIsBeforeFieldInit.AnnotatedMethod--", ProducedBy = ProducedBy.Analyzer)]
public static int field = AnnotatedMethod ();
[RequiresUnreferencedCode ("Message from --TypeIsBeforeFieldInit.AnnotatedMethod--")]
+ [RequiresAssemblyFiles ("Message from --TypeIsBeforeFieldInit.AnnotatedMethod--")]
public static int AnnotatedMethod () => 42;
}
@@ -416,19 +458,24 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class StaticCtorTriggeredByMethodCall
{
+ // TODO: Analyzer still allows RUC/RAF on static constructor with no warning
+ // https://github.com/dotnet/linker/issues/2347
[ExpectedWarning ("IL2116", "StaticCtorTriggeredByMethodCall..cctor()", ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("Message for --StaticCtorTriggeredByMethodCall.Cctor--")]
+ [RequiresAssemblyFiles ("Message for --StaticCtorTriggeredByMethodCall.Cctor--")]
static StaticCtorTriggeredByMethodCall ()
{
}
[RequiresUnreferencedCode ("Message for --StaticCtorTriggeredByMethodCall.TriggerStaticCtorMarking--")]
+ [RequiresAssemblyFiles ("Message for --StaticCtorTriggeredByMethodCall.TriggerStaticCtorMarking--")]
public void TriggerStaticCtorMarking ()
{
}
}
[ExpectedWarning ("IL2026", "--StaticCtorTriggeredByMethodCall.TriggerStaticCtorMarking--")]
+ [ExpectedWarning ("IL3002", "--StaticCtorTriggeredByMethodCall.TriggerStaticCtorMarking--", ProducedBy = ProducedBy.Analyzer)]
static void TestStaticCtorTriggeredByMethodCall ()
{
new StaticCtorTriggeredByMethodCall ().TriggerStaticCtorMarking ();
@@ -449,6 +496,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
[LogDoesNotContain ("ImplementationClass.MethodWithRequires")]
[ExpectedWarning ("IL2026", "--IRequires.MethodWithRequires--")]
+ [ExpectedWarning ("IL3002", "--IRequires.MethodWithRequires--", ProducedBy = ProducedBy.Analyzer)]
static void TestInterfaceMethodWithRequires ()
{
IRequires inst = new ImplementationClass ();
@@ -461,12 +509,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
interface IRequires
{
[RequiresUnreferencedCode ("Message for --IRequires.MethodWithRequires--")]
+ [RequiresAssemblyFiles ("Message for --IRequires.MethodWithRequires--")]
public void MethodWithRequires ();
}
class ImplementationClass : IRequires
{
[RequiresUnreferencedCode ("Message for --ImplementationClass.RequiresMethod--")]
+ [RequiresAssemblyFiles ("Message for --ImplementationClass.RequiresMethod--")]
public void MethodWithRequires ()
{
}
@@ -475,12 +525,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
abstract class CovariantReturnBase
{
[RequiresUnreferencedCode ("Message for --CovariantReturnBase.GetRequires--")]
+ [RequiresAssemblyFiles ("Message for --CovariantReturnBase.GetRequires--")]
public abstract BaseReturnType GetRequires ();
}
class CovariantReturnDerived : CovariantReturnBase
{
[RequiresUnreferencedCode ("Message for --CovariantReturnDerived.GetRequires--")]
+ [RequiresAssemblyFiles ("Message for --CovariantReturnDerived.GetRequires--")]
public override DerivedReturnType GetRequires ()
{
return null;
@@ -489,6 +541,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
[LogDoesNotContain ("--CovariantReturnBase.GetRequires--")]
[ExpectedWarning ("IL2026", "--CovariantReturnDerived.GetRequires--")]
+ [ExpectedWarning ("IL3002", "--CovariantReturnDerived.GetRequires--", ProducedBy = ProducedBy.Analyzer)]
static void TestCovariantReturnCallOnDerived ()
{
var tmp = new CovariantReturnDerived ();
@@ -496,6 +549,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", "--Method--")]
+ [ExpectedWarning ("IL3002", "--Method--", ProducedBy = ProducedBy.Analyzer)]
static void TestRequiresInMethodFromCopiedAssembly ()
{
var tmp = new RequiresInCopyAssembly ();
@@ -516,11 +570,13 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Message for --RequiresInDynamicDependency--")]
+ [RequiresAssemblyFiles ("Message for --RequiresInDynamicDependency--")]
static void RequiresInDynamicDependency ()
{
}
[ExpectedWarning ("IL2026", "--RequiresInDynamicDependency--")]
+ [ExpectedWarning ("IL3002", "--RequiresInDynamicDependency--", ProducedBy = ProducedBy.Analyzer)]
[DynamicDependency ("RequiresInDynamicDependency")]
static void TestRequiresInDynamicDependency ()
{
@@ -528,22 +584,27 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Linker adds a trailing period to this message")]
+ [RequiresAssemblyFiles ("Linker adds a trailing period to this message")]
static void WarningMessageWithoutEndingPeriod ()
{
}
[ExpectedWarning ("IL2026", "Linker adds a trailing period to this message.")]
+ [ExpectedWarning ("IL3002", "Linker adds a trailing period to this message.", ProducedBy = ProducedBy.Analyzer)]
static void TestThatTrailingPeriodIsAddedToMessage ()
{
WarningMessageWithoutEndingPeriod ();
}
[RequiresUnreferencedCode ("Linker does not add a period to this message.")]
+ [RequiresAssemblyFiles ("Linker does not add a period to this message.")]
static void WarningMessageEndsWithPeriod ()
{
}
+ [LogDoesNotContain ("Linker does not add a period to this message..")]
[ExpectedWarning ("IL2026", "Linker does not add a period to this message.")]
+ [ExpectedWarning ("IL3002", "Linker does not add a period to this message.", ProducedBy = ProducedBy.Analyzer)]
static void TestThatTrailingPeriodIsNotDuplicatedInWarningMessage ()
{
WarningMessageEndsWithPeriod ();
@@ -570,6 +631,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class AttributeWhichRequiresAttribute : Attribute
{
[RequiresUnreferencedCode ("Message for --AttributeWhichRequiresAttribute.ctor--")]
+ [RequiresAssemblyFiles ("Message for --AttributeWhichRequiresAttribute.ctor--")]
public AttributeWhichRequiresAttribute ()
{
}
@@ -585,17 +647,20 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
get => false;
[RequiresUnreferencedCode ("--AttributeWhichRequiresOnPropertyAttribute.PropertyWhichRequires--")]
+ [RequiresAssemblyFiles ("--AttributeWhichRequiresOnPropertyAttribute.PropertyWhichRequires--")]
set { }
}
}
[ExpectedWarning ("IL2026", "--AttributeWhichRequiresAttribute.ctor--")]
+ [ExpectedWarning ("IL3002", "--AttributeWhichRequiresAttribute.ctor--", ProducedBy = ProducedBy.Analyzer)]
class GenericTypeWithAttributedParameter<[AttributeWhichRequires] T>
{
public static void TestMethod () { }
}
[ExpectedWarning ("IL2026", "--AttributeWhichRequiresAttribute.ctor--")]
+ [ExpectedWarning ("IL3002", "--AttributeWhichRequiresAttribute.ctor--", ProducedBy = ProducedBy.Analyzer)]
static void GenericMethodWithAttributedParameter<[AttributeWhichRequires] T> () { }
static void TestRequiresOnAttributeOnGenericParameter ()
@@ -605,7 +670,9 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", "--AttributeWhichRequiresAttribute.ctor--")]
+ [ExpectedWarning ("IL3002", "--AttributeWhichRequiresAttribute.ctor--", ProducedBy = ProducedBy.Analyzer)]
[ExpectedWarning ("IL2026", "--AttributeWhichRequiresOnPropertyAttribute.PropertyWhichRequires--")]
+ [ExpectedWarning ("IL3002", "--AttributeWhichRequiresOnPropertyAttribute.PropertyWhichRequires--", ProducedBy = ProducedBy.Analyzer)]
[AttributeWhichRequires]
[AttributeWhichRequiresOnProperty (PropertyWhichRequires = true)]
class TypeWithAttributeWhichRequires
@@ -613,19 +680,25 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", "--AttributeWhichRequiresAttribute.ctor--")]
+ [ExpectedWarning ("IL3002", "--AttributeWhichRequiresAttribute.ctor--", ProducedBy = ProducedBy.Analyzer)]
[ExpectedWarning ("IL2026", "--AttributeWhichRequiresOnPropertyAttribute.PropertyWhichRequires--")]
+ [ExpectedWarning ("IL3002", "--AttributeWhichRequiresOnPropertyAttribute.PropertyWhichRequires--", ProducedBy = ProducedBy.Analyzer)]
[AttributeWhichRequires]
[AttributeWhichRequiresOnProperty (PropertyWhichRequires = true)]
static void MethodWithAttributeWhichRequires () { }
[ExpectedWarning ("IL2026", "--AttributeWhichRequiresAttribute.ctor--")]
+ [ExpectedWarning ("IL3002", "--AttributeWhichRequiresAttribute.ctor--", ProducedBy = ProducedBy.Analyzer)]
[ExpectedWarning ("IL2026", "--AttributeWhichRequiresOnPropertyAttribute.PropertyWhichRequires--")]
+ [ExpectedWarning ("IL3002", "--AttributeWhichRequiresOnPropertyAttribute.PropertyWhichRequires--", ProducedBy = ProducedBy.Analyzer)]
[AttributeWhichRequires]
[AttributeWhichRequiresOnProperty (PropertyWhichRequires = true)]
static int _fieldWithAttributeWhichRequires;
[ExpectedWarning ("IL2026", "--AttributeWhichRequiresAttribute.ctor--")]
+ [ExpectedWarning ("IL3002", "--AttributeWhichRequiresAttribute.ctor--", ProducedBy = ProducedBy.Analyzer)]
[ExpectedWarning ("IL2026", "--AttributeWhichRequiresOnPropertyAttribute.PropertyWhichRequires--")]
+ [ExpectedWarning ("IL3002", "--AttributeWhichRequiresOnPropertyAttribute.PropertyWhichRequires--", ProducedBy = ProducedBy.Analyzer)]
[AttributeWhichRequires]
[AttributeWhichRequiresOnProperty (PropertyWhichRequires = true)]
static bool PropertyWithAttributeWhichRequires { get; set; }
@@ -633,9 +706,11 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
[AttributeWhichRequires]
[AttributeWhichRequiresOnProperty (PropertyWhichRequires = true)]
[RequiresUnreferencedCode ("--MethodWhichRequiresWithAttributeWhichRequires--")]
+ [RequiresAssemblyFiles ("--MethodWhichRequiresWithAttributeWhichRequires--")]
static void MethodWhichRequiresWithAttributeWhichRequires () { }
[ExpectedWarning ("IL2026", "--MethodWhichRequiresWithAttributeWhichRequires--")]
+ [ExpectedWarning ("IL3002", "--MethodWhichRequiresWithAttributeWhichRequires--", ProducedBy = ProducedBy.Analyzer)]
static void TestMethodWhichRequiresWithAttributeWhichRequires ()
{
MethodWhichRequiresWithAttributeWhichRequires ();
@@ -662,10 +737,12 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class GenericWithStaticMethod<T>
{
[RequiresUnreferencedCode ("Message for --GenericTypeWithStaticMethodWhichRequires--")]
+ [RequiresAssemblyFiles ("Message for --GenericTypeWithStaticMethodWhichRequires--")]
public static void GenericTypeWithStaticMethodWhichRequires () { }
}
[ExpectedWarning ("IL2026", "--GenericTypeWithStaticMethodWhichRequires--")]
+ [ExpectedWarning ("IL3002", "--GenericTypeWithStaticMethodWhichRequires--", ProducedBy = ProducedBy.Analyzer)]
public static void GenericTypeWithStaticMethodViaLdftn ()
{
var _ = new Action (GenericWithStaticMethod<TestType>.GenericTypeWithStaticMethodWhichRequires);
@@ -682,12 +759,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
abstract class Base
{
[RequiresUnreferencedCode ("Message for --CovariantReturnViaLdftn.Base.GetRequires--")]
+ [RequiresAssemblyFiles ("Message for --CovariantReturnViaLdftn.Base.GetRequires--")]
public abstract BaseReturnType GetRequires ();
}
class Derived : Base
{
[RequiresUnreferencedCode ("Message for --CovariantReturnViaLdftn.Derived.GetRequires--")]
+ [RequiresAssemblyFiles ("Message for --CovariantReturnViaLdftn.Derived.GetRequires--")]
public override DerivedReturnType GetRequires ()
{
return null;
@@ -695,6 +774,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", "--CovariantReturnViaLdftn.Derived.GetRequires--")]
+ [ExpectedWarning ("IL3002", "--CovariantReturnViaLdftn.Derived.GetRequires--", ProducedBy = ProducedBy.Analyzer)]
public static void Test ()
{
var tmp = new Derived ();
@@ -748,18 +828,22 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
static event EventHandler EventToTestRemove {
add { }
[RequiresUnreferencedCode ("Message for --EventToTestRemove.remove--")]
+ [RequiresAssemblyFiles ("Message for --EventToTestRemove.remove--")]
remove { }
}
[ExpectedWarning ("IL2026", "--EventToTestAdd.add--", ProducedBy = ProducedBy.Trimmer)]
static event EventHandler EventToTestAdd {
[RequiresUnreferencedCode ("Message for --EventToTestAdd.add--")]
+ [RequiresAssemblyFiles ("Message for --EventToTestAdd.add--")]
add { }
remove { }
}
[ExpectedWarning ("IL2026", "--EventToTestRemove.remove--")]
+ [ExpectedWarning ("IL3002", "--EventToTestRemove.remove--", ProducedBy = ProducedBy.Analyzer)]
[ExpectedWarning ("IL2026", "--EventToTestAdd.add--")]
+ [ExpectedWarning ("IL3002", "--EventToTestAdd.add--", ProducedBy = ProducedBy.Analyzer)]
public static void Test ()
{
EventToTestRemove -= (sender, e) => { };
@@ -772,12 +856,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class NewConstraintTestType
{
[RequiresUnreferencedCode ("Message for --NewConstraintTestType.ctor--")]
+ [RequiresAssemblyFiles ("Message for --NewConstraintTestType.ctor--")]
public NewConstraintTestType () { }
}
static void GenericMethod<T> () where T : new() { }
[ExpectedWarning ("IL2026", "--NewConstraintTestType.ctor--")]
+ [ExpectedWarning ("IL3002", "--NewConstraintTestType.ctor--", ProducedBy = ProducedBy.Analyzer)]
public static void Test ()
{
GenericMethod<NewConstraintTestType> ();
@@ -793,12 +879,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", "--NewConstraintTestType.ctor--")]
+ [ExpectedWarning ("IL3002", "--NewConstraintTestType.ctor--", ProducedBy = ProducedBy.Analyzer)]
public static void TestNewConstraintOnTypeParameter ()
{
_ = new NewConstaintOnTypeParameter<NewConstraintTestType> ();
}
[ExpectedWarning ("IL2026", "--NewConstraintTestType.ctor--")]
+ [ExpectedWarning ("IL3002", "--NewConstraintTestType.ctor--", ProducedBy = ProducedBy.Analyzer)]
public static void TestNewConstraintOnTypeParameterOfStaticType ()
{
NewConstraintOnTypeParameterOfStaticType<NewConstraintTestType>.DoNothing ();
@@ -809,18 +897,283 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
{
static bool PropertyWithLdToken {
[RequiresUnreferencedCode ("Message for --PropertyWithLdToken.get--")]
+ [RequiresAssemblyFiles ("Message for --PropertyWithLdToken.get--")]
get {
return false;
}
}
[ExpectedWarning ("IL2026", "--PropertyWithLdToken.get--")]
+ [ExpectedWarning ("IL3002", "--PropertyWithLdToken.get--", ProducedBy = ProducedBy.Analyzer)]
public static void Test ()
{
Expression<Func<bool>> getter = () => PropertyWithLdToken;
}
}
+ class AttributeMismatch
+ {
+ static void RequirePublicMethods ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type type)
+ {
+ }
+
+ class BaseClassWithRequires
+ {
+ [RequiresUnreferencedCode ("Message")]
+ [RequiresAssemblyFiles ("Message")]
+ public virtual void VirtualMethod ()
+ {
+ }
+
+ public virtual string VirtualPropertyAnnotationInAccesor {
+ [RequiresUnreferencedCode ("Message")]
+ [RequiresAssemblyFiles ("Message")]
+ get;
+ set;
+ }
+
+ [RequiresAssemblyFiles ("Message")]
+ public virtual string VirtualPropertyAnnotationInProperty { get; set; }
+ }
+
+ class BaseClassWithoutRequires
+ {
+ public virtual void VirtualMethod ()
+ {
+ }
+
+ public virtual string VirtualPropertyAnnotationInAccesor { get; set; }
+
+ public virtual string VirtualPropertyAnnotationInProperty { get; set; }
+ }
+
+ class DerivedClassWithRequires : BaseClassWithoutRequires
+ {
+ [RequiresUnreferencedCode ("Message")]
+ [RequiresAssemblyFiles ("Message")]
+ [ExpectedWarning ("IL2046", "DerivedClassWithRequires.VirtualMethod()", "BaseClassWithoutRequires.VirtualMethod()")]
+ [ExpectedWarning ("IL3003", "DerivedClassWithRequires.VirtualMethod()", "BaseClassWithoutRequires.VirtualMethod()", ProducedBy = ProducedBy.Analyzer)]
+ public override void VirtualMethod ()
+ {
+ }
+
+ private string name;
+ public override string VirtualPropertyAnnotationInAccesor {
+ [ExpectedWarning ("IL2046", "DerivedClassWithRequires.VirtualPropertyAnnotationInAccesor.get", "BaseClassWithoutRequires.VirtualPropertyAnnotationInAccesor.get")]
+ [ExpectedWarning ("IL3003", "DerivedClassWithRequires.VirtualPropertyAnnotationInAccesor.get", "BaseClassWithoutRequires.VirtualPropertyAnnotationInAccesor.get", ProducedBy = ProducedBy.Analyzer)]
+ [RequiresUnreferencedCode ("Message")]
+ [RequiresAssemblyFiles ("Message")]
+ get { return name; }
+ set { name = value; }
+ }
+
+ [RequiresAssemblyFiles ("Message")]
+ [ExpectedWarning ("IL3003", "DerivedClassWithRequires.VirtualPropertyAnnotationInProperty", "BaseClassWithoutRequires.VirtualPropertyAnnotationInProperty", ProducedBy = ProducedBy.Analyzer)]
+ public override string VirtualPropertyAnnotationInProperty { get; set; }
+ }
+
+ class DerivedClassWithoutRequires : BaseClassWithRequires
+ {
+ [ExpectedWarning ("IL2046", "DerivedClassWithoutRequires.VirtualMethod()", "BaseClassWithRequires.VirtualMethod()")]
+ [ExpectedWarning ("IL3003", "DerivedClassWithoutRequires.VirtualMethod()", "BaseClassWithRequires.VirtualMethod()", ProducedBy = ProducedBy.Analyzer)]
+ public override void VirtualMethod ()
+ {
+ }
+
+ private string name;
+ public override string VirtualPropertyAnnotationInAccesor {
+ [ExpectedWarning ("IL2046", "DerivedClassWithoutRequires.VirtualPropertyAnnotationInAccesor.get", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.get")]
+ [ExpectedWarning ("IL3003", "DerivedClassWithoutRequires.VirtualPropertyAnnotationInAccesor.get", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.get", ProducedBy = ProducedBy.Analyzer)]
+ get { return name; }
+ set { name = value; }
+ }
+
+ [ExpectedWarning ("IL3003", "DerivedClassWithoutRequires.VirtualPropertyAnnotationInProperty", "BaseClassWithRequires.VirtualPropertyAnnotationInProperty", ProducedBy = ProducedBy.Analyzer)]
+ public override string VirtualPropertyAnnotationInProperty { get; set; }
+ }
+
+ public interface IBaseWithRequires
+ {
+ [RequiresUnreferencedCode ("Message")]
+ [RequiresAssemblyFiles ("Message")]
+ void Method ();
+
+ string PropertyAnnotationInAccesor {
+ [RequiresUnreferencedCode ("Message")]
+ [RequiresAssemblyFiles ("Message")]
+ get;
+ set;
+ }
+
+ [RequiresAssemblyFiles ("Message")]
+ string PropertyAnnotationInProperty { get; set; }
+ }
+
+ public interface IBaseWithoutRequires
+ {
+ void Method ();
+
+ string PropertyAnnotationInAccesor { get; set; }
+
+ string PropertyAnnotationInProperty { get; set; }
+ }
+
+ class ImplementationClassWithRequires : IBaseWithoutRequires
+ {
+ [RequiresUnreferencedCode ("Message")]
+ [RequiresAssemblyFiles ("Message")]
+ [ExpectedWarning ("IL2046", "ImplementationClassWithRequires.Method()", "IBaseWithoutRequires.Method()")]
+ [ExpectedWarning ("IL3003", "ImplementationClassWithRequires.Method()", "IBaseWithoutRequires.Method()", ProducedBy = ProducedBy.Analyzer)]
+ public void Method ()
+ {
+ }
+
+ private string name;
+ public string PropertyAnnotationInAccesor {
+ [ExpectedWarning ("IL2046", "ImplementationClassWithRequires.PropertyAnnotationInAccesor.get", "IBaseWithoutRequires.PropertyAnnotationInAccesor.get")]
+ [ExpectedWarning ("IL3003", "ImplementationClassWithRequires.PropertyAnnotationInAccesor.get", "IBaseWithoutRequires.PropertyAnnotationInAccesor.get", ProducedBy = ProducedBy.Analyzer)]
+ [RequiresUnreferencedCode ("Message")]
+ [RequiresAssemblyFiles ("Message")]
+ get { return name; }
+ set { name = value; }
+ }
+
+ [RequiresAssemblyFiles ("Message")]
+ [ExpectedWarning ("IL3003", "ImplementationClassWithRequires.PropertyAnnotationInProperty", "IBaseWithoutRequires.PropertyAnnotationInProperty", ProducedBy = ProducedBy.Analyzer)]
+ public string PropertyAnnotationInProperty { get; set; }
+ }
+
+ class ExplicitImplementationClassWithRequires : IBaseWithoutRequires
+ {
+ [RequiresUnreferencedCode ("Message")]
+ [RequiresAssemblyFiles ("Message")]
+ [ExpectedWarning ("IL2046", "ExplicitImplementationClassWithRequires.Mono.Linker.Tests.Cases.RequiresCapability.RequiresCapability.AttributeMismatch.IBaseWithoutRequires.Method()", "IBaseWithoutRequires.Method()")]
+ [ExpectedWarning ("IL3003", "ExplicitImplementationClassWithRequires.Mono.Linker.Tests.Cases.RequiresCapability.RequiresCapability.AttributeMismatch.IBaseWithoutRequires.Method()", "IBaseWithoutRequires.Method()", ProducedBy = ProducedBy.Analyzer)]
+ void IBaseWithoutRequires.Method ()
+ {
+ }
+
+ private string name;
+ string IBaseWithoutRequires.PropertyAnnotationInAccesor {
+ [ExpectedWarning ("IL2046", "PropertyAnnotationInAccesor.get", "IBaseWithoutRequires.PropertyAnnotationInAccesor.get")]
+ [ExpectedWarning ("IL3003", "PropertyAnnotationInAccesor.get", "IBaseWithoutRequires.PropertyAnnotationInAccesor.get", ProducedBy = ProducedBy.Analyzer)]
+ [RequiresUnreferencedCode ("Message")]
+ [RequiresAssemblyFiles ("Message")]
+ get { return name; }
+ set { name = value; }
+ }
+
+ [RequiresAssemblyFiles ("Message")]
+ [ExpectedWarning ("IL3003", "ExplicitImplementationClassWithRequires.Mono.Linker.Tests.Cases.RequiresCapability.RequiresCapability.AttributeMismatch.IBaseWithoutRequires.PropertyAnnotationInProperty", "IBaseWithoutRequires.PropertyAnnotationInProperty", ProducedBy = ProducedBy.Analyzer)]
+ string IBaseWithoutRequires.PropertyAnnotationInProperty { get; set; }
+ }
+
+ class ImplementationClassWithoutRequires : IBaseWithRequires
+ {
+ [ExpectedWarning ("IL2046", "ImplementationClassWithoutRequires.Method()", "IBaseWithRequires.Method()")]
+ [ExpectedWarning ("IL3003", "ImplementationClassWithoutRequires.Method()", "IBaseWithRequires.Method()", ProducedBy = ProducedBy.Analyzer)]
+ public void Method ()
+ {
+ }
+
+ private string name;
+ public string PropertyAnnotationInAccesor {
+ [ExpectedWarning ("IL2046", "ImplementationClassWithoutRequires.PropertyAnnotationInAccesor.get", "IBaseWithRequires.PropertyAnnotationInAccesor.get")]
+ [ExpectedWarning ("IL3003", "ImplementationClassWithoutRequires.PropertyAnnotationInAccesor.get", "IBaseWithRequires.PropertyAnnotationInAccesor.get", ProducedBy = ProducedBy.Analyzer)]
+ get { return name; }
+ set { name = value; }
+ }
+
+ [ExpectedWarning ("IL3003", "ImplementationClassWithoutRequires.PropertyAnnotationInProperty", "IBaseWithRequires.PropertyAnnotationInProperty", ProducedBy = ProducedBy.Analyzer)]
+ public string PropertyAnnotationInProperty { get; set; }
+ }
+
+ class ExplicitImplementationClassWithoutRequires : IBaseWithRequires
+ {
+ [ExpectedWarning ("IL2046", "IBaseWithRequires.Method()", "ExplicitImplementationClassWithoutRequires.Mono.Linker.Tests.Cases.RequiresCapability.RequiresCapability.AttributeMismatch.IBaseWithRequires.Method()")]
+ [ExpectedWarning ("IL3003", "IBaseWithRequires.Method()", "ExplicitImplementationClassWithoutRequires.Mono.Linker.Tests.Cases.RequiresCapability.RequiresCapability.AttributeMismatch.IBaseWithRequires.Method()", ProducedBy = ProducedBy.Analyzer)]
+ void IBaseWithRequires.Method ()
+ {
+ }
+
+ private string name;
+ string IBaseWithRequires.PropertyAnnotationInAccesor {
+ [ExpectedWarning ("IL2046", "PropertyAnnotationInAccesor.get", "IBaseWithRequires.PropertyAnnotationInAccesor.get")]
+ [ExpectedWarning ("IL3003", "PropertyAnnotationInAccesor.get", "IBaseWithRequires.PropertyAnnotationInAccesor.get", ProducedBy = ProducedBy.Analyzer)]
+ get { return name; }
+ set { name = value; }
+ }
+
+ [ExpectedWarning ("IL3003", "ExplicitImplementationClassWithoutRequires.Mono.Linker.Tests.Cases.RequiresCapability.RequiresCapability.AttributeMismatch.IBaseWithRequires.PropertyAnnotationInProperty", "IBaseWithRequires.PropertyAnnotationInProperty", ProducedBy = ProducedBy.Analyzer)]
+ string IBaseWithRequires.PropertyAnnotationInProperty { get; set; }
+ }
+
+ class ImplementationClassWithoutRequiresInSource : ReferenceInterfaces.IBaseWithRequiresInReference
+ {
+ [ExpectedWarning ("IL2046", "ImplementationClassWithoutRequiresInSource.Method()", "IBaseWithRequiresInReference.Method()")]
+ [ExpectedWarning ("IL3003", "ImplementationClassWithoutRequiresInSource.Method()", "IBaseWithRequiresInReference.Method()", ProducedBy = ProducedBy.Analyzer)]
+ public void Method ()
+ {
+ }
+
+ private string name;
+ public string PropertyAnnotationInAccesor {
+ [ExpectedWarning ("IL2046", "ImplementationClassWithoutRequiresInSource.PropertyAnnotationInAccesor.get", "IBaseWithRequiresInReference.PropertyAnnotationInAccesor.get")]
+ [ExpectedWarning ("IL3003", "ImplementationClassWithoutRequiresInSource.PropertyAnnotationInAccesor.get", "IBaseWithRequiresInReference.PropertyAnnotationInAccesor.get", ProducedBy = ProducedBy.Analyzer)]
+ get { return name; }
+ set { name = value; }
+ }
+
+ [ExpectedWarning ("IL3003", "ImplementationClassWithoutRequiresInSource.PropertyAnnotationInProperty", "IBaseWithRequiresInReference.PropertyAnnotationInProperty", ProducedBy = ProducedBy.Analyzer)]
+ public string PropertyAnnotationInProperty { get; set; }
+ }
+
+ class ImplementationClassWithRequiresInSource : ReferenceInterfaces.IBaseWithoutRequiresInReference
+ {
+ [ExpectedWarning ("IL2046", "ImplementationClassWithRequiresInSource.Method()", "IBaseWithoutRequiresInReference.Method()")]
+ [ExpectedWarning ("IL3003", "ImplementationClassWithRequiresInSource.Method()", "IBaseWithoutRequiresInReference.Method()", ProducedBy = ProducedBy.Analyzer)]
+ [RequiresUnreferencedCode ("Message")]
+ [RequiresAssemblyFiles ("Message")]
+ public void Method ()
+ {
+ }
+
+ private string name;
+ public string PropertyAnnotationInAccesor {
+ [ExpectedWarning ("IL2046", "ImplementationClassWithRequiresInSource.PropertyAnnotationInAccesor.get", "IBaseWithoutRequiresInReference.PropertyAnnotationInAccesor.get")]
+ [ExpectedWarning ("IL3003", "ImplementationClassWithRequiresInSource.PropertyAnnotationInAccesor.get", "IBaseWithoutRequiresInReference.PropertyAnnotationInAccesor.get", ProducedBy = ProducedBy.Analyzer)]
+ [RequiresUnreferencedCode ("Message")]
+ [RequiresAssemblyFiles ("Message")]
+ get { return name; }
+ set { name = value; }
+ }
+
+ [ExpectedWarning ("IL3003", "ImplementationClassWithRequiresInSource.PropertyAnnotationInProperty", "IBaseWithoutRequiresInReference.PropertyAnnotationInProperty", ProducedBy = ProducedBy.Analyzer)]
+ [RequiresAssemblyFiles ("Message")]
+ public string PropertyAnnotationInProperty { get; set; }
+ }
+
+ [ExpectedWarning ("IL2026", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.get", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "BaseClassWithRequires.VirtualMethod()", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "IBaseWithRequires.PropertyAnnotationInAccesor.get", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2026", "IBaseWithRequires.Method()", ProducedBy = ProducedBy.Trimmer)]
+ public static void Test ()
+ {
+ RequirePublicMethods (typeof (BaseClassWithRequires));
+ RequirePublicMethods (typeof (BaseClassWithoutRequires));
+ RequirePublicMethods (typeof (DerivedClassWithRequires));
+ RequirePublicMethods (typeof (DerivedClassWithoutRequires));
+ RequirePublicMethods (typeof (IBaseWithRequires));
+ RequirePublicMethods (typeof (IBaseWithoutRequires));
+ RequirePublicMethods (typeof (ImplementationClassWithRequires));
+ RequirePublicMethods (typeof (ImplementationClassWithoutRequires));
+ RequirePublicMethods (typeof (ExplicitImplementationClassWithRequires));
+ RequirePublicMethods (typeof (ExplicitImplementationClassWithoutRequires));
+ RequirePublicMethods (typeof (ImplementationClassWithoutRequiresInSource));
+ RequirePublicMethods (typeof (ImplementationClassWithRequiresInSource));
+ }
+ }
+
class RequiresOnClass
{
[RequiresUnreferencedCode ("Message for --ClassWithRequires--")]
diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityFromCopiedAssembly.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityFromCopiedAssembly.cs
index b30833564..6036d7044 100644
--- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityFromCopiedAssembly.cs
+++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresCapabilityFromCopiedAssembly.cs
@@ -11,6 +11,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
[SetupCompileBefore ("lib.dll", new[] { "Dependencies/RequiresInCopyAssembly.cs" })]
[KeptAllTypesAndMembersInAssembly ("lib.dll")]
[LogDoesNotContain ("IL2026")]
+ [LogDoesNotContain ("IL3002")]
[LogDoesNotContain ("IL2027")]
public class RequiresCapabilityFromCopiedAssembly
{
diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs
index dbbb7fc18..e5f176d87 100644
--- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs
+++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs
@@ -44,6 +44,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class WarnInIteratorBody
{
[ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = ProducedBy.Analyzer)]
static IEnumerable<int> TestCallBeforeYieldReturn ()
{
MethodWithRequires ();
@@ -51,6 +52,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = ProducedBy.Analyzer)]
static IEnumerable<int> TestCallAfterYieldReturn ()
{
yield return 0;
@@ -68,6 +70,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = ProducedBy.Analyzer)]
static IEnumerable<int> TestLdftn ()
{
yield return 0;
@@ -75,6 +78,18 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
var action = new Action (MethodWithRequires);
}
+ // Cannot annotate fields either with RUC nor RAF therefore the warning persists
+ [ExpectedWarning ("IL2026", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", ProducedBy = ProducedBy.Analyzer)]
+ public static Lazy<string> _default = new Lazy<string> (MethodWithRequiresAndReturns);
+
+ static IEnumerable<int> TestLazyDelegate ()
+ {
+ yield return 0;
+ yield return 1;
+ _ = _default.Value;
+ }
+
[ExpectedWarning ("IL2026", "--TypeWithMethodWithRequires.MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
static IEnumerable<int> TestDynamicallyAccessedMethod ()
{
@@ -89,6 +104,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
TestCallAfterYieldReturn ();
TestReflectionAccess ();
TestLdftn ();
+ TestLazyDelegate ();
TestDynamicallyAccessedMethod ();
}
}
@@ -96,6 +112,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class SuppressInIteratorBody
{
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static IEnumerable<int> TestCall ()
{
MethodWithRequires ();
@@ -105,6 +122,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static IEnumerable<int> TestReflectionAccess ()
{
yield return 0;
@@ -115,6 +133,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static IEnumerable<int> TestLdftn ()
{
yield return 0;
@@ -122,7 +141,20 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
var action = new Action (MethodWithRequires);
}
+ // Cannot annotate fields either with RUC nor RAF therefore the warning persists
+ [ExpectedWarning ("IL2026", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", ProducedBy = ProducedBy.Analyzer)]
+ public static Lazy<string> _default = new Lazy<string> (MethodWithRequiresAndReturns);
+
+ static IEnumerable<int> TestLazyDelegate ()
+ {
+ yield return 0;
+ yield return 1;
+ _ = _default.Value;
+ }
+
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static IEnumerable<int> TestDynamicallyAccessedMethod ()
{
typeof (TypeWithMethodWithRequires).RequiresNonPublicMethods ();
@@ -131,6 +163,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static IEnumerable<int> TestMethodParameterWithRequirements (Type unknownType = null)
{
unknownType.RequiresNonPublicMethods ();
@@ -138,6 +171,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static IEnumerable<int> TestGenericMethodParameterRequirement<TUnknown> ()
{
MethodWithGenericWhichRequiresMethods<TUnknown> ();
@@ -145,6 +179,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static IEnumerable<int> TestGenericTypeParameterRequirement<TUnknown> ()
{
new TypeWithGenericWhichRequiresNonPublicFields<TUnknown> ();
@@ -152,11 +187,13 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[UnconditionalSuppressMessage ("Trimming", "IL2026")]
+ [UnconditionalSuppressMessage ("SingleFile", "IL3002")]
public static void Test ()
{
TestCall ();
TestReflectionAccess ();
TestLdftn ();
+ TestLazyDelegate ();
TestDynamicallyAccessedMethod ();
TestMethodParameterWithRequirements ();
TestGenericMethodParameterRequirement<TestType> ();
@@ -167,6 +204,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class WarnInAsyncBody
{
[ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = ProducedBy.Analyzer)]
static async void TestCallBeforeYieldReturn ()
{
MethodWithRequires ();
@@ -174,6 +212,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = ProducedBy.Analyzer)]
static async void TestCallAfterYieldReturn ()
{
await MethodAsync ();
@@ -191,12 +230,23 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = ProducedBy.Analyzer)]
static async void TestLdftn ()
{
await MethodAsync ();
var action = new Action (MethodWithRequires);
}
+ [ExpectedWarning ("IL2026", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", ProducedBy = ProducedBy.Analyzer)]
+ public static Lazy<string> _default = new Lazy<string> (MethodWithRequiresAndReturns);
+
+ static async void TestLazyDelegate ()
+ {
+ await MethodAsync ();
+ _ = _default.Value;
+ }
+
[ExpectedWarning ("IL2026", "--TypeWithMethodWithRequires.MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
static async void TestDynamicallyAccessedMethod ()
{
@@ -210,6 +260,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
TestCallAfterYieldReturn ();
TestReflectionAccess ();
TestLdftn ();
+ TestLazyDelegate ();
TestDynamicallyAccessedMethod ();
}
}
@@ -217,6 +268,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class SuppressInAsyncBody
{
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async void TestCall ()
{
MethodWithRequires ();
@@ -226,6 +278,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async void TestReflectionAccess ()
{
await MethodAsync ();
@@ -236,13 +289,26 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async void TestLdftn ()
{
await MethodAsync ();
var action = new Action (MethodWithRequires);
}
+ // Cannot annotate fields either with RUC nor RAF therefore the warning persists
+ [ExpectedWarning ("IL2026", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", ProducedBy = ProducedBy.Analyzer)]
+ public static Lazy<string> _default = new Lazy<string> (MethodWithRequiresAndReturns);
+
+ static async void TestLazyDelegate ()
+ {
+ await MethodAsync ();
+ _ = _default.Value;
+ }
+
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async void TestDynamicallyAccessedMethod ()
{
typeof (TypeWithMethodWithRequires).RequiresNonPublicMethods ();
@@ -250,6 +316,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async void TestMethodParameterWithRequirements (Type unknownType = null)
{
unknownType.RequiresNonPublicMethods ();
@@ -257,6 +324,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async void TestGenericMethodParameterRequirement<TUnknown> ()
{
MethodWithGenericWhichRequiresMethods<TUnknown> ();
@@ -264,6 +332,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async void TestGenericTypeParameterRequirement<TUnknown> ()
{
new TypeWithGenericWhichRequiresNonPublicFields<TUnknown> ();
@@ -271,11 +340,13 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[UnconditionalSuppressMessage ("Trimming", "IL2026")]
+ [UnconditionalSuppressMessage ("SingleFile", "IL3002")]
public static void Test ()
{
TestCall ();
TestReflectionAccess ();
TestLdftn ();
+ TestLazyDelegate ();
TestDynamicallyAccessedMethod ();
TestMethodParameterWithRequirements ();
TestGenericMethodParameterRequirement<TestType> ();
@@ -286,6 +357,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class WarnInAsyncIteratorBody
{
[ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = ProducedBy.Analyzer)]
static async IAsyncEnumerable<int> TestCallBeforeYieldReturn ()
{
await MethodAsync ();
@@ -294,6 +366,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = ProducedBy.Analyzer)]
static async IAsyncEnumerable<int> TestCallAfterYieldReturn ()
{
yield return 0;
@@ -314,6 +387,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = ProducedBy.Analyzer)]
static async IAsyncEnumerable<int> TestLdftn ()
{
await MethodAsync ();
@@ -321,6 +395,17 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
var action = new Action (MethodWithRequires);
}
+ [ExpectedWarning ("IL2026", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", ProducedBy = ProducedBy.Analyzer)]
+ public static Lazy<string> _default = new Lazy<string> (MethodWithRequiresAndReturns);
+
+ static async IAsyncEnumerable<int> TestLazyDelegate ()
+ {
+ await MethodAsync ();
+ yield return 0;
+ _ = _default.Value;
+ }
+
[ExpectedWarning ("IL2026", "--TypeWithMethodWithRequires.MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
static async IAsyncEnumerable<int> TestDynamicallyAccessedMethod ()
{
@@ -335,6 +420,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
TestCallAfterYieldReturn ();
TestReflectionAccess ();
TestLdftn ();
+ TestLazyDelegate ();
TestDynamicallyAccessedMethod ();
}
}
@@ -342,6 +428,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class SuppressInAsyncIteratorBody
{
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async IAsyncEnumerable<int> TestCall ()
{
MethodWithRequires ();
@@ -352,6 +439,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async IAsyncEnumerable<int> TestReflectionAccess ()
{
await MethodAsync ();
@@ -364,6 +452,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async IAsyncEnumerable<int> TestLdftn ()
{
await MethodAsync ();
@@ -371,7 +460,20 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
yield return 0;
}
+ // Cannot annotate fields either with RUC nor RAF therefore the warning persists
+ [ExpectedWarning ("IL2026", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", ProducedBy = ProducedBy.Analyzer)]
+ public static Lazy<string> _default = new Lazy<string> (MethodWithRequiresAndReturns);
+
+ static async IAsyncEnumerable<int> TestLazyDelegate ()
+ {
+ await MethodAsync ();
+ yield return 0;
+ _ = _default.Value;
+ }
+
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async IAsyncEnumerable<int> TestDynamicallyAccessedMethod ()
{
typeof (TypeWithMethodWithRequires).RequiresNonPublicMethods ();
@@ -380,6 +482,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async IAsyncEnumerable<int> TestMethodParameterWithRequirements (Type unknownType = null)
{
unknownType.RequiresNonPublicMethods ();
@@ -388,6 +491,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async IAsyncEnumerable<int> TestGenericMethodParameterRequirement<TUnknown> ()
{
yield return 0;
@@ -396,6 +500,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async IAsyncEnumerable<int> TestGenericTypeParameterRequirement<TUnknown> ()
{
new TypeWithGenericWhichRequiresNonPublicFields<TUnknown> ();
@@ -404,11 +509,13 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[UnconditionalSuppressMessage ("Trimming", "IL2026")]
+ [UnconditionalSuppressMessage ("SingleFile", "IL3002")]
public static void Test ()
{
TestCall ();
TestReflectionAccess ();
TestLdftn ();
+ TestLazyDelegate ();
TestDynamicallyAccessedMethod ();
TestMethodParameterWithRequirements ();
TestGenericMethodParameterRequirement<TestType> ();
@@ -419,6 +526,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class WarnInLocalFunction
{
[ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = ProducedBy.Analyzer)]
static void TestCall ()
{
LocalFunction ();
@@ -427,6 +535,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = ProducedBy.Analyzer)]
static void TestCallWithClosure (int p = 0)
{
LocalFunction ();
@@ -449,6 +558,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = ProducedBy.Analyzer)]
static void TestLdftn ()
{
LocalFunction ();
@@ -459,6 +569,20 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
}
+ [ExpectedWarning ("IL2026", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", ProducedBy = ProducedBy.Analyzer)]
+ public static Lazy<string> _default = new Lazy<string> (MethodWithRequiresAndReturns);
+
+ static void TestLazyDelegate ()
+ {
+ LocalFunction ();
+
+ void LocalFunction ()
+ {
+ _ = _default.Value;
+ }
+ }
+
[ExpectedWarning ("IL2026", "--TypeWithMethodWithRequires.MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
static void TestDynamicallyAccessedMethod ()
{
@@ -473,6 +597,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
TestCallWithClosure ();
TestReflectionAccess ();
TestLdftn ();
+ TestLazyDelegate ();
TestDynamicallyAccessedMethod ();
}
}
@@ -483,20 +608,24 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
// so its suppression effect also doesn't propagate
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static void TestCall ()
{
LocalFunction ();
[ExpectedWarning ("IL2026")]
+ [ExpectedWarning ("IL3002", ProducedBy = ProducedBy.Analyzer)]
void LocalFunction () => MethodWithRequires ();
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static void TestCallWithClosure (int p = 0)
{
LocalFunction ();
[ExpectedWarning ("IL2026")]
+ [ExpectedWarning ("IL3002", ProducedBy = ProducedBy.Analyzer)]
void LocalFunction ()
{
p++;
@@ -505,38 +634,59 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async void TestReflectionAccess ()
{
LocalFunction ();
[ExpectedWarning ("IL2026")]
+ [ExpectedWarning ("IL3002", ProducedBy = ProducedBy.Analyzer)]
void LocalFunction () => typeof (RequiresInCompilerGeneratedCode)
.GetMethod ("MethodWithRequires", System.Reflection.BindingFlags.NonPublic)
.Invoke (null, new object[] { });
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async void TestLdftn ()
{
LocalFunction ();
[ExpectedWarning ("IL2026")]
+ [ExpectedWarning ("IL3002", ProducedBy = ProducedBy.Analyzer)]
void LocalFunction ()
{
var action = new Action (MethodWithRequires);
}
}
+ [ExpectedWarning ("IL2026", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", ProducedBy = ProducedBy.Analyzer)]
+ public static Lazy<string> _default = new Lazy<string> (MethodWithRequiresAndReturns);
+
+ static void TestLazyDelegate ()
+ {
+ LocalFunction ();
+
+ void LocalFunction ()
+ {
+ _ = _default.Value;
+ }
+ }
+
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async void TestDynamicallyAccessedMethod ()
{
LocalFunction ();
[ExpectedWarning ("IL2026")]
+ [ExpectedWarning ("IL3002", ProducedBy = ProducedBy.Analyzer)]
void LocalFunction () => typeof (TypeWithMethodWithRequires).RequiresNonPublicMethods ();
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async void TestMethodParameterWithRequirements (Type unknownType = null)
{
LocalFunction ();
@@ -546,6 +696,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static void TestGenericMethodParameterRequirement<TUnknown> ()
{
LocalFunction ();
@@ -555,6 +706,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static void TestGenericTypeParameterRequirement<TUnknown> ()
{
LocalFunction ();
@@ -564,6 +716,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static void TestGenericLocalFunction<TUnknown> ()
{
LocalFunction<TUnknown> ();
@@ -575,6 +728,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static void TestGenericLocalFunctionInner<TUnknown> ()
{
LocalFunction<TUnknown> ();
@@ -611,32 +765,38 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static void TestCallMethodWithRequiresInLtftnLocalFunction ()
{
var _ = new Action (LocalFunction);
[ExpectedWarning ("IL2026")]
+ [ExpectedWarning ("IL3002", ProducedBy = ProducedBy.Analyzer)]
void LocalFunction () => MethodWithRequires ();
}
class DynamicallyAccessedLocalFunction
{
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
public static void TestCallMethodWithRequiresInDynamicallyAccessedLocalFunction ()
{
typeof (DynamicallyAccessedLocalFunction).RequiresNonPublicMethods ();
[ExpectedWarning ("IL2026")]
+ [ExpectedWarning ("IL3002", ProducedBy = ProducedBy.Analyzer)]
void LocalFunction () => MethodWithRequires ();
}
}
[ExpectedWarning ("IL2026")]
+ [ExpectedWarning ("IL3002", ProducedBy = ProducedBy.Analyzer)]
static void TestSuppressionLocalFunction ()
{
LocalFunction (); // This will produce a warning since the location function has Requires on it
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
void LocalFunction (Type unknownType = null)
{
MethodWithRequires ();
@@ -645,11 +805,13 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static void TestSuppressionOnOuterAndLocalFunction ()
{
LocalFunction ();
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
void LocalFunction (Type unknownType = null)
{
MethodWithRequires ();
@@ -658,12 +820,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[UnconditionalSuppressMessage ("Trimming", "IL2026")]
+ [UnconditionalSuppressMessage ("SingleFile", "IL3002")]
public static void Test ()
{
TestCall ();
TestCallWithClosure ();
TestReflectionAccess ();
TestLdftn ();
+ TestLazyDelegate ();
TestMethodParameterWithRequirements ();
TestDynamicallyAccessedMethod ();
TestGenericMethodParameterRequirement<TestType> ();
@@ -682,12 +846,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class WarnInLambda
{
[ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = ProducedBy.Analyzer)]
static void TestCall ()
{
Action _ = () => MethodWithRequires ();
}
[ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = ProducedBy.Analyzer)]
static void TestCallWithClosure (int p = 0)
{
Action _ = () => {
@@ -707,6 +873,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = ProducedBy.Analyzer)]
static void TestLdftn ()
{
Action _ = () => {
@@ -714,6 +881,17 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
};
}
+ [ExpectedWarning ("IL2026", "--MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "--MethodWithRequiresAndReturns--", ProducedBy = ProducedBy.Analyzer)]
+ public static Lazy<string> _default = new Lazy<string> (MethodWithRequiresAndReturns);
+
+ static void TestLazyDelegate ()
+ {
+ Action _ = () => {
+ var action = _default.Value;
+ };
+ }
+
[ExpectedWarning ("IL2026", "--TypeWithMethodWithRequires.MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
static void TestDynamicallyAccessedMethod ()
{
@@ -728,6 +906,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
TestCallWithClosure ();
TestReflectionAccess ();
TestLdftn ();
+ TestLazyDelegate ();
TestDynamicallyAccessedMethod ();
}
}
@@ -741,7 +920,9 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
// - Would be useful for testing - have to use the CompilerGeneratedCode = true trick instead
[ExpectedWarning ("IL2026", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", ProducedBy = ProducedBy.Analyzer)]
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static void TestCall ()
{
Action _ = () => MethodWithRequires ();
@@ -750,6 +931,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, ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static void TestCallWithReflectionAnalysisWarning ()
{
// This should not produce warning because the Requires
@@ -757,7 +939,9 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", ProducedBy = ProducedBy.Analyzer)]
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static void TestCallWithClosure (int p = 0)
{
Action _ = () => {
@@ -769,6 +953,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
// Analyzer doesn't recognize reflection access - so doesn't warn in this case
[ExpectedWarning ("IL2026", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static void TestReflectionAccess ()
{
Action _ = () => {
@@ -779,7 +964,9 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", ProducedBy = ProducedBy.Analyzer)]
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static void TestLdftn ()
{
Action _ = () => {
@@ -787,9 +974,21 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
};
}
+ [ExpectedWarning ("IL2026", "--MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "--MethodWithRequiresAndReturns--", ProducedBy = ProducedBy.Analyzer)]
+ public static Lazy<string> _default = new Lazy<string> (MethodWithRequiresAndReturns);
+
+ static void TestLazyDelegate ()
+ {
+ Action _ = () => {
+ var action = _default.Value;
+ };
+ }
+
// Analyzer doesn't apply DAM - so won't see this warnings
[ExpectedWarning ("IL2026", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static void TestDynamicallyAccessedMethod ()
{
Action _ = () => {
@@ -800,6 +999,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, ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async void TestMethodParameterWithRequirements (Type unknownType = null)
{
Action _ = () => unknownType.RequiresNonPublicMethods ();
@@ -808,6 +1008,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, ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static void TestGenericMethodParameterRequirement<TUnknown> ()
{
Action _ = () => {
@@ -818,6 +1019,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, ProducedBy = ProducedBy.Trimmer)]
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static void TestGenericTypeParameterRequirement<TUnknown> ()
{
Action _ = () => {
@@ -826,6 +1028,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[UnconditionalSuppressMessage ("Trimming", "IL2026")]
+ [UnconditionalSuppressMessage ("SingleFile", "IL3002")]
public static void Test ()
{
TestCall ();
@@ -833,6 +1036,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
TestCallWithClosure ();
TestReflectionAccess ();
TestLdftn ();
+ TestLazyDelegate ();
TestDynamicallyAccessedMethod ();
TestMethodParameterWithRequirements ();
TestGenericMethodParameterRequirement<TestType> ();
@@ -843,6 +1047,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class WarnInComplex
{
[ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = ProducedBy.Analyzer)]
static async void TestIteratorLocalFunctionInAsync ()
{
await MethodAsync ();
@@ -874,6 +1079,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class SuppressInComplex
{
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async void TestIteratorLocalFunctionInAsync ()
{
await MethodAsync ();
@@ -881,6 +1087,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
await MethodAsync ();
[RequiresUnreferencedCode ("Suppress in local function")]
+ [RequiresAssemblyFiles ("Suppress in local function")]
IEnumerable<int> LocalFunction ()
{
yield return 0;
@@ -890,6 +1097,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static async void TestIteratorLocalFunctionInAsyncWithoutInner ()
{
await MethodAsync ();
@@ -897,6 +1105,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
await MethodAsync ();
[ExpectedWarning ("IL2026", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", ProducedBy = ProducedBy.Analyzer)]
IEnumerable<int> LocalFunction ()
{
yield return 0;
@@ -906,6 +1115,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Suppress in body")]
+ [RequiresAssemblyFiles ("Suppress in body")]
static IEnumerable<int> TestDynamicallyAccessedMethodViaGenericMethodParameterInIterator ()
{
MethodWithGenericWhichRequiresMethods<TypeWithMethodWithRequires> ();
@@ -913,6 +1123,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[UnconditionalSuppressMessage ("Trimming", "IL2026")]
+ [UnconditionalSuppressMessage ("SingleFile", "IL3002")]
public static void Test ()
{
TestIteratorLocalFunctionInAsync ();
@@ -924,6 +1135,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class StateMachinesOnlyReferencedViaReflection
{
[RequiresUnreferencedCode ("Requires to suppress")]
+ [RequiresAssemblyFiles ("Requires to suppress")]
static IEnumerable<int> TestIteratorOnlyReferencedViaReflectionWhichShouldSuppress ()
{
yield return 0;
@@ -931,6 +1143,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("Requires to suppress")]
+ [RequiresAssemblyFiles ("Requires to suppress")]
static async void TestAsyncOnlyReferencedViaReflectionWhichShouldSuppress ()
{
await MethodAsync ();
@@ -938,6 +1151,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", ProducedBy = ProducedBy.Analyzer)]
static IEnumerable<int> TestIteratorOnlyReferencedViaReflectionWhichShouldWarn ()
{
yield return 0;
@@ -945,6 +1159,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", CompilerGeneratedCode = true)]
+ [ExpectedWarning ("IL3002", ProducedBy = ProducedBy.Analyzer)]
static async void TestAsyncOnlyReferencedViaReflectionWhichShouldWarn ()
{
await MethodAsync ();
@@ -966,12 +1181,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
public class AsyncBodyCallingMethodWithRequires
{
[RequiresUnreferencedCode ("")]
+ [RequiresAssemblyFiles ("")]
static Task<object> MethodWithRequiresAsync (Type type)
{
return Task.FromResult (new object ());
}
[RequiresUnreferencedCode ("ParentSuppression")]
+ [RequiresAssemblyFiles ("ParentSuppression")]
static async Task<object> AsyncMethodCallingRequires (Type type)
{
using (var diposable = await GetDisposableAsync ()) {
@@ -980,6 +1197,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", "ParentSuppression")]
+ [ExpectedWarning ("IL3002", "ParentSuppression", ProducedBy = ProducedBy.Analyzer)]
public static void Test ()
{
AsyncMethodCallingRequires (typeof (object));
@@ -989,12 +1207,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
public class GenericAsyncBodyCallingMethodWithRequires
{
[RequiresUnreferencedCode ("")]
+ [RequiresAssemblyFiles ("")]
static ValueTask<TValue> MethodWithRequiresAsync<TValue> ()
{
return ValueTask.FromResult (default (TValue));
}
[RequiresUnreferencedCode ("ParentSuppression")]
+ [RequiresAssemblyFiles ("ParentSuppression")]
static async Task<T> AsyncMethodCallingRequires<T> ()
{
using (var disposable = await GetDisposableAsync ()) {
@@ -1003,6 +1223,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", "ParentSuppression")]
+ [ExpectedWarning ("IL3002", "ParentSuppression", ProducedBy = ProducedBy.Analyzer)]
public static void Test ()
{
AsyncMethodCallingRequires<object> ();
@@ -1014,12 +1235,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class RequiresOnCtor
{
[RequiresUnreferencedCode ("")]
+ [RequiresAssemblyFiles ("")]
public RequiresOnCtor ()
{
}
}
[RequiresUnreferencedCode ("ParentSuppression")]
+ [RequiresAssemblyFiles ("ParentSuppression")]
static IAsyncEnumerable<TValue> AsyncEnumMethodCallingRequires<
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicProperties)] TValue> ()
{
@@ -1035,6 +1258,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[ExpectedWarning ("IL2026", "ParentSuppression")]
+ [ExpectedWarning ("IL3002", "ParentSuppression", ProducedBy = ProducedBy.Analyzer)]
public static void Test ()
{
AsyncEnumMethodCallingRequires<object> ();
@@ -1052,6 +1276,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
}
[RequiresUnreferencedCode ("--MethodWithRequires--")]
+ [RequiresAssemblyFiles ("--MethodWithRequires--")]
static void MethodWithRequires ()
{
}
@@ -1059,11 +1284,19 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class TypeWithMethodWithRequires
{
[RequiresUnreferencedCode ("--TypeWithMethodWithRequires.MethodWithRequires--")]
+ [RequiresAssemblyFiles ("--TypeWithMethodWithRequires.MethodWithRequires--")]
static void MethodWithRequires ()
{
}
}
+ [RequiresUnreferencedCode ("Message from --MethodWithRequiresAndReturns--")]
+ [RequiresAssemblyFiles ("Message from --MethodWithRequiresAndReturns--")]
+ public static string MethodWithRequiresAndReturns ()
+ {
+ return "string";
+ }
+
static void MethodWithGenericWhichRequiresMethods<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicMethods)] T> ()
{
}
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
index bab3a4f59..949029edc 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
@@ -777,6 +777,9 @@ namespace Mono.Linker.Tests.TestCasesRunner
if (actualName.StartsWith (expectedMember.DeclaringType.FullName) &&
actualName.Contains ("<" + expectedMember.Name + ">"))
return true;
+ if (actualName.StartsWith (expectedMember.DeclaringType.FullName) &&
+ actualName.Contains (".cctor") && (expectedMember is FieldDefinition || expectedMember is PropertyDefinition))
+ return true;
if (methodDefinition.Name == ".ctor" &&
methodDefinition.DeclaringType.FullName == expectedMember.FullName)
return true;