From 10af5e04fdab9075832e6c3fa6a4f68d325f08a1 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Mon, 4 Nov 2024 14:12:03 -0800 Subject: [PATCH] Revert "Fix missing analyzer warning for generics in containing type (#109392)" (#109520) This reverts commit ed778146626f560ebb14ec69167d0b8f537dacbc. Fixes a timeout in CLR_Tools_Tests. --- .../TrimAnalysis/GenericArgumentDataFlow.cs | 9 +--- .../RequiresCapabilityTests.cs | 6 --- .../DataFlowTests.g.cs | 6 --- .../DataFlow/GenericParameterDataFlow.cs | 54 ------------------- 4 files changed, 2 insertions(+), 73 deletions(-) diff --git a/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/GenericArgumentDataFlow.cs b/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/GenericArgumentDataFlow.cs index 5dd24d55b2a40..b3d0a97a4ab5e 100644 --- a/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/GenericArgumentDataFlow.cs +++ b/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/GenericArgumentDataFlow.cs @@ -14,10 +14,7 @@ internal static class GenericArgumentDataFlow { public static void ProcessGenericArgumentDataFlow (Location location, INamedTypeSymbol type, Action reportDiagnostic) { - while (type is { IsGenericType: true }) { - ProcessGenericArgumentDataFlow (location, type.TypeArguments, type.TypeParameters, reportDiagnostic); - type = type.ContainingType; - } + ProcessGenericArgumentDataFlow (location, type.TypeArguments, type.TypeParameters, reportDiagnostic); } public static void ProcessGenericArgumentDataFlow (Location location, IMethodSymbol method, Action reportDiagnostic) @@ -58,7 +55,7 @@ static void ProcessGenericArgumentDataFlow ( public static bool RequiresGenericArgumentDataFlow (INamedTypeSymbol type) { - while (type is { IsGenericType: true }) { + if (type.IsGenericType) { if (RequiresGenericArgumentDataFlow (type.TypeParameters)) return true; @@ -67,8 +64,6 @@ public static bool RequiresGenericArgumentDataFlow (INamedTypeSymbol type) && RequiresGenericArgumentDataFlow (namedTypeSymbol)) return true; } - - type = type.ContainingType; } return false; diff --git a/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/RequiresCapabilityTests.cs b/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/RequiresCapabilityTests.cs index da855966b0b3b..3f722ad634e3d 100644 --- a/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/RequiresCapabilityTests.cs +++ b/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/RequiresCapabilityTests.cs @@ -64,12 +64,6 @@ public Task RequiresInLibraryAssembly () return RunTest (); } - [Fact] - public Task RequiresInRootAllAssembly () - { - return RunTest (); - } - [Fact] public Task RequiresOnAttribute () { diff --git a/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/DataFlowTests.g.cs b/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/DataFlowTests.g.cs index a50e4dfd16075..95dfd9c0f72a0 100644 --- a/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/DataFlowTests.g.cs +++ b/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/DataFlowTests.g.cs @@ -31,12 +31,6 @@ public Task MethodByRefParameterDataFlow () return RunTest (allowMissingWarnings: true); } - [Fact] - public Task ModifierDataFlow () - { - return RunTest (allowMissingWarnings: true); - } - [Fact] public Task StaticInterfaceMethodDataflow () { diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs index 2200b59e980f8..2cbd62f6d4343 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs @@ -48,7 +48,6 @@ public static void Main () TestNoWarningsInRUCMethod (); TestNoWarningsInRUCType (); - TestGenericParameterFlowsToNestedType.Test (); } static void TestSingleGenericParameterOnType () @@ -850,59 +849,6 @@ static void TestNoWarningsInRUCType () rucType.VirtualMethodRequiresPublicMethods (); } - class TestGenericParameterFlowsToNestedType - { - class Generic { - [ExpectedWarning ("IL2091")] - public T CallNestedMethod () => GenericRequires.Nested.Method (); - - [ExpectedWarning ("IL2091")] - public T AccessNestedField () => GenericRequires.Nested.Field; - - [ExpectedWarning ("IL2091")] - public T AccessNestedProperty () => GenericRequires.Nested.Property; - - [ExpectedWarning ("IL2091")] - public void AccessNestedEvent () => GenericRequires.Nested.Event += null; - - [ExpectedWarning ("IL2091")] - public void UseNestedTypeArgument () { - new Generic.Nested> (); - } - - [ExpectedWarning ("IL2091")] - public class DerivedFromNestedType : GenericRequires.Nested - { - [ExpectedWarning ("IL2091")] - public DerivedFromNestedType () { - } - } - } - - class GenericRequires<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T> { - public class Nested { - public static T? Method () => default; - - public static T? Field = default; - - public static T? Property { get; set; } = default; - - public static event Action? Event; - } - } - - public static void Test () - { - var instance = new Generic (); - instance.CallNestedMethod (); - instance.AccessNestedField (); - instance.AccessNestedProperty (); - instance.AccessNestedEvent (); - instance.UseNestedTypeArgument (); - new Generic.DerivedFromNestedType (); - } - } - [RequiresUnreferencedCode ("message")] public class RUCTypeRequiresPublicFields< [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] T>