diff options
Diffstat (limited to 'test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs')
-rw-r--r-- | test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs | 232 |
1 files changed, 232 insertions, 0 deletions
diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs index 26777a1a8..0adbae0d6 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,22 +765,26 @@ 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 (); } } @@ -640,6 +798,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability 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 (); @@ -648,11 +807,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 (); @@ -661,12 +822,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> (); @@ -685,12 +848,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 _ = () => { @@ -710,6 +875,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)] + [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = ProducedBy.Analyzer)] static void TestLdftn () { Action _ = () => { @@ -717,6 +883,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 () { @@ -731,6 +908,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability TestCallWithClosure (); TestReflectionAccess (); TestLdftn (); + TestLazyDelegate (); TestDynamicallyAccessedMethod (); } } @@ -744,7 +922,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 (); @@ -752,6 +932,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability [ExpectedWarning ("IL2067", CompilerGeneratedCode = true)] [RequiresUnreferencedCode ("Suppress in body")] + [RequiresAssemblyFiles ("Suppress in body")] static void TestCallWithReflectionAnalysisWarning () { // This should not produce warning because the Requires @@ -759,7 +940,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 _ = () => { @@ -771,6 +954,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 _ = () => { @@ -781,7 +965,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 _ = () => { @@ -789,9 +975,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 _ = () => { @@ -804,6 +1002,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability [ExpectedWarning ("IL2077", CompilerGeneratedCode = true, ProducedBy = ProducedBy.Trimmer)] [ExpectedWarning ("IL2067", ProducedBy = ProducedBy.Analyzer)] [RequiresUnreferencedCode ("Suppress in body")] + [RequiresAssemblyFiles ("Suppress in body")] static async void TestMethodParameterWithRequirements (Type unknownType = null) { Action _ = () => unknownType.RequiresNonPublicMethods (); @@ -811,6 +1010,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability [ExpectedWarning ("IL2091", CompilerGeneratedCode = true)] [RequiresUnreferencedCode ("Suppress in body")] + [RequiresAssemblyFiles ("Suppress in body")] static void TestGenericMethodParameterRequirement<TUnknown> () { Action _ = () => { @@ -821,6 +1021,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 _ = () => { @@ -829,6 +1030,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [UnconditionalSuppressMessage ("Trimming", "IL2026")] + [UnconditionalSuppressMessage ("SingleFile", "IL3002")] public static void Test () { TestCall (); @@ -836,6 +1038,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability TestCallWithClosure (); TestReflectionAccess (); TestLdftn (); + TestLazyDelegate (); TestDynamicallyAccessedMethod (); TestMethodParameterWithRequirements (); TestGenericMethodParameterRequirement<TestType> (); @@ -846,6 +1049,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 (); @@ -877,6 +1081,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability class SuppressInComplex { [RequiresUnreferencedCode ("Suppress in body")] + [RequiresAssemblyFiles ("Suppress in body")] static async void TestIteratorLocalFunctionInAsync () { await MethodAsync (); @@ -884,6 +1089,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; @@ -893,6 +1099,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [RequiresUnreferencedCode ("Suppress in body")] + [RequiresAssemblyFiles ("Suppress in body")] static async void TestIteratorLocalFunctionInAsyncWithoutInner () { await MethodAsync (); @@ -900,6 +1107,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability await MethodAsync (); [ExpectedWarning ("IL2026", CompilerGeneratedCode = true)] + [ExpectedWarning ("IL3002", ProducedBy = ProducedBy.Analyzer)] IEnumerable<int> LocalFunction () { yield return 0; @@ -909,6 +1117,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [RequiresUnreferencedCode ("Suppress in body")] + [RequiresAssemblyFiles ("Suppress in body")] static IEnumerable<int> TestDynamicallyAccessedMethodViaGenericMethodParameterInIterator () { MethodWithGenericWhichRequiresMethods<TypeWithMethodWithRequires> (); @@ -916,6 +1125,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [UnconditionalSuppressMessage ("Trimming", "IL2026")] + [UnconditionalSuppressMessage ("SingleFile", "IL3002")] public static void Test () { TestIteratorLocalFunctionInAsync (); @@ -927,6 +1137,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability class StateMachinesOnlyReferencedViaReflection { [RequiresUnreferencedCode ("Requires to suppress")] + [RequiresAssemblyFiles ("Requires to suppress")] static IEnumerable<int> TestIteratorOnlyReferencedViaReflectionWhichShouldSuppress () { yield return 0; @@ -934,6 +1145,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [RequiresUnreferencedCode ("Requires to suppress")] + [RequiresAssemblyFiles ("Requires to suppress")] static async void TestAsyncOnlyReferencedViaReflectionWhichShouldSuppress () { await MethodAsync (); @@ -941,6 +1153,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [ExpectedWarning ("IL2026", CompilerGeneratedCode = true)] + [ExpectedWarning ("IL3002", ProducedBy = ProducedBy.Analyzer)] static IEnumerable<int> TestIteratorOnlyReferencedViaReflectionWhichShouldWarn () { yield return 0; @@ -948,6 +1161,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [ExpectedWarning ("IL2026", CompilerGeneratedCode = true)] + [ExpectedWarning ("IL3002", ProducedBy = ProducedBy.Analyzer)] static async void TestAsyncOnlyReferencedViaReflectionWhichShouldWarn () { await MethodAsync (); @@ -969,12 +1183,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 ()) { @@ -983,6 +1199,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [ExpectedWarning ("IL2026", "ParentSuppression")] + [ExpectedWarning ("IL3002", "ParentSuppression", ProducedBy = ProducedBy.Analyzer)] public static void Test () { AsyncMethodCallingRequires (typeof (object)); @@ -992,12 +1209,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 ()) { @@ -1006,6 +1225,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [ExpectedWarning ("IL2026", "ParentSuppression")] + [ExpectedWarning ("IL3002", "ParentSuppression", ProducedBy = ProducedBy.Analyzer)] public static void Test () { AsyncMethodCallingRequires<object> (); @@ -1017,12 +1237,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> () { @@ -1038,6 +1260,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [ExpectedWarning ("IL2026", "ParentSuppression")] + [ExpectedWarning ("IL3002", "ParentSuppression", ProducedBy = ProducedBy.Analyzer)] public static void Test () { AsyncEnumMethodCallingRequires<object> (); @@ -1055,6 +1278,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability } [RequiresUnreferencedCode ("--MethodWithRequires--")] + [RequiresAssemblyFiles ("--MethodWithRequires--")] static void MethodWithRequires () { } @@ -1062,11 +1286,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> () { } |