diff options
author | Sven Boemer <sbomer@gmail.com> | 2022-02-16 23:43:44 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-16 23:43:44 +0300 |
commit | 60bce42bd5e2386678ae977e5a935ebe2bf91fe4 (patch) | |
tree | 88fc52810af22d7744e607995e8859e4c0599e82 /test | |
parent | 9f21028e0db39e9a68c057e9ab0a73b6f019dd80 (diff) |
[DAM analyzer] Analyze exception filters (#2593)
This adds support for exception filters in the analyzer. Now the exception state will flow from from try blocks to any catch blocks without filters, or to the filter regions of any catch blocks that do have filters. Additionally, the dataflow state flows from a filter region to the next filter or catch. We don't check whether the exception type of the filter regions match, but conservatively assume that control can flow out of any filter to the next filter or catch.
This also assumes that control leaves the filter region from its last block - I don't know if there are cases where a filter region can contain more than one basic block, so if this is possible the logic might need to be updated.
I added a few testcases with dataflow and side effects in filter regions. This fixes https://github.com/dotnet/linker/issues/2415 and allows enabling two more of the previously failing tests.
Diffstat (limited to 'test')
3 files changed, 224 insertions, 46 deletions
diff --git a/test/ILLink.RoslynAnalyzer.Tests/AdvancedTests.cs b/test/ILLink.RoslynAnalyzer.Tests/AdvancedTests.cs index aae7de9d7..69de25e4e 100644 --- a/test/ILLink.RoslynAnalyzer.Tests/AdvancedTests.cs +++ b/test/ILLink.RoslynAnalyzer.Tests/AdvancedTests.cs @@ -7,7 +7,7 @@ namespace ILLink.RoslynAnalyzer.Tests { protected override string TestSuiteName => "Advanced"; - [Fact (Skip = "https://github.com/dotnet/linker/issues/2415")] + [Fact] public Task TypeCheckRemoval () { return RunTest (allowMissingWarnings: true); diff --git a/test/ILLink.RoslynAnalyzer.Tests/UnreachableBlockTests.cs b/test/ILLink.RoslynAnalyzer.Tests/UnreachableBlockTests.cs index 67eac2546..9b7947a6d 100644 --- a/test/ILLink.RoslynAnalyzer.Tests/UnreachableBlockTests.cs +++ b/test/ILLink.RoslynAnalyzer.Tests/UnreachableBlockTests.cs @@ -7,7 +7,7 @@ namespace ILLink.RoslynAnalyzer.Tests { protected override string TestSuiteName => "UnreachableBlock"; - [Fact (Skip = "https://github.com/dotnet/linker/issues/2415")] + [Fact] public Task TryFilterBlocks () { return RunTest (allowMissingWarnings: true); diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/ExceptionalDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/ExceptionalDataFlow.cs index 40bf18ca7..fd1dcd474 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/ExceptionalDataFlow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/ExceptionalDataFlow.cs @@ -5,6 +5,7 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; namespace Mono.Linker.Tests.Cases.DataFlow { [SkipKeptItemsValidation] + [ExpectedNoWarnings] public class ExceptionalDataFlow { public static void Main () @@ -36,6 +37,11 @@ namespace Mono.Linker.Tests.Cases.DataFlow FinallyInTryWithPredecessor (); NestedFinally (); NestedFinallyWithPredecessor (); + ExceptionFilter (); + ExceptionFilterStateChange (); + ExceptionMultipleFilters (); + ExceptionFilterWithBranch (); + ExceptionFilterWithException (); } [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields) + "()", @@ -114,6 +120,14 @@ namespace Mono.Linker.Tests.Cases.DataFlow [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicEvents) + "()")] [ExpectedWarning ("IL2073", nameof (MultipleFinallyPaths) + "()", nameof (GetWithPublicEvents) + "()")] + + // Linker merges branches going forward. + [ExpectedWarning ("IL2073", nameof (MultipleFinallyPaths) + "()", nameof (GetWithPublicMethods) + "()", + ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2073", nameof (MultipleFinallyPaths) + "()", nameof (GetWithPublicFields) + "()", + ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2073", nameof (MultipleFinallyPaths) + "()", nameof (GetWithPublicProperties) + "()", + ProducedBy = ProducedBy.Trimmer)] [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] public static Type MultipleFinallyPaths () { @@ -252,8 +266,6 @@ namespace Mono.Linker.Tests.Cases.DataFlow RequireAll (t); } - - [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods) + "()", ProducedBy = ProducedBy.Analyzer)] [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicProperties) + "()")] @@ -297,23 +309,41 @@ namespace Mono.Linker.Tests.Cases.DataFlow [ExpectedWarning ("IL2072", nameof (RequireAll4) + "(Type)", nameof (GetWithPublicMethods) + "()", ProducedBy = ProducedBy.Analyzer)] - [ExpectedWarning ("IL2072", nameof (RequireAll4) + "(Type)", nameof (GetWithPublicFields) + "()", - ProducedBy = ProducedBy.Analyzer)] + [ExpectedWarning ("IL2072", nameof (RequireAll4) + "(Type)", nameof (GetWithPublicFields) + "()")] [ExpectedWarning ("IL2072", nameof (RequireAll5) + "(Type)", nameof (GetWithPublicEvents) + "()")] [ExpectedWarning ("IL2072", nameof (RequireAll6) + "(Type)", nameof (GetWithPublicMethods) + "()", ProducedBy = ProducedBy.Analyzer)] - [ExpectedWarning ("IL2072", nameof (RequireAll6) + "(Type)", nameof (GetWithPublicFields) + "()", - ProducedBy = ProducedBy.Analyzer)] - [ExpectedWarning ("IL2072", nameof (RequireAll6) + "(Type)", nameof (GetWithPublicProperties) + "()", - ProducedBy = ProducedBy.Analyzer)] + [ExpectedWarning ("IL2072", nameof (RequireAll6) + "(Type)", nameof (GetWithPublicFields) + "()")] + [ExpectedWarning ("IL2072", nameof (RequireAll6) + "(Type)", nameof (GetWithPublicProperties) + "()")] [ExpectedWarning ("IL2072", nameof (RequireAll6) + "(Type)", nameof (GetWithPublicEvents) + "()")] [ExpectedWarning ("IL2072", nameof (RequireAll7) + "(Type)", nameof (GetWithPublicConstructors) + "()")] [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicConstructors) + "()")] + // Linker merges branches going forward. + [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicFields) + "()", + ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2072", nameof (RequireAll4) + "(Type)", nameof (GetWithPublicProperties) + "()", + ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2072", nameof (RequireAll5) + "(Type)", nameof (GetWithPublicFields) + "()", + ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2072", nameof (RequireAll5) + "(Type)", nameof (GetWithPublicProperties) + "()", + ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2072", nameof (RequireAll7) + "(Type)", nameof (GetWithPublicFields) + "()", + ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2072", nameof (RequireAll7) + "(Type)", nameof (GetWithPublicProperties) + "()", + ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2072", nameof (RequireAll7) + "(Type)", nameof (GetWithPublicEvents) + "()", + ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields) + "()", + ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicProperties) + "()", + ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicEvents) + "()", + ProducedBy = ProducedBy.Trimmer)] public static void TryFlowsToMultipleCatchAndFinally () { @@ -352,8 +382,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow ProducedBy = ProducedBy.Analyzer)] [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicEvents) + "()", ProducedBy = ProducedBy.Analyzer)] - [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicConstructors) + "()", - ProducedBy = ProducedBy.Analyzer)] + [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicConstructors) + "()")] public static void NestedWithFinally () { @@ -383,16 +412,13 @@ namespace Mono.Linker.Tests.Cases.DataFlow [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicMethods) + "()", ProducedBy = ProducedBy.Analyzer)] - [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields) + "()", - ProducedBy = ProducedBy.Analyzer)] + [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields) + "()")] [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicProperties) + "()")] [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicMethods) + "()", ProducedBy = ProducedBy.Analyzer)] - [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicFields) + "()", - ProducedBy = ProducedBy.Analyzer)] - [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicProperties) + "()", - ProducedBy = ProducedBy.Analyzer)] + [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicFields) + "()")] + [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicProperties) + "()")] [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicEvents) + "()")] public static void ControlFlowsOutOfMultipleFinally () { @@ -459,6 +485,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow } [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields) + "()")] + // Linker merges branches going forward. + [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods) + "()", + ProducedBy = ProducedBy.Trimmer)] public static void CatchInTry () { try { @@ -480,6 +509,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields) + "()")] // The bug was producing this warning: // [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicConstructors) + "()")] + + // Linker merges branches going forward. + [ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicMethods) + "()", + ProducedBy = ProducedBy.Trimmer)] public static void CatchInTryWithFinally () { Type t = GetWithPublicConstructors (); @@ -507,6 +540,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods) + "()")] + // Linker merges branches going forward. + [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields) + "()", + ProducedBy = ProducedBy.Trimmer)] public static void TestCatchesHaveSeparateState () { Type t = GetWithPublicMethods (); @@ -670,11 +706,14 @@ namespace Mono.Linker.Tests.Cases.DataFlow [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicMethods) + "()", ProducedBy = ProducedBy.Analyzer)] - [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields) + "()", - ProducedBy = ProducedBy.Analyzer)] + [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields) + "()")] [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicProperties) + "()")] [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicProperties) + "()")] + + // Linker merges branches going forward. + [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicFields) + "()", + ProducedBy = ProducedBy.Trimmer)] public static void NestedFinally () { Type t = GetWithPublicMethods (); @@ -697,11 +736,14 @@ namespace Mono.Linker.Tests.Cases.DataFlow [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicMethods) + "()", ProducedBy = ProducedBy.Analyzer)] - [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields) + "()", - ProducedBy = ProducedBy.Analyzer)] + [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields) + "()")] [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicProperties) + "()")] [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicProperties) + "()")] + + // Linker merges branches going forward. + [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicFields) + "()", + ProducedBy = ProducedBy.Trimmer)] public static void NestedFinallyWithPredecessor () { Type t = GetWithPublicMethods (); @@ -719,55 +761,191 @@ namespace Mono.Linker.Tests.Cases.DataFlow } } - [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] - public static Type GetWithPublicMethods () + [ExpectedWarning ("IL2072", nameof (RequireAllTrue) + "(Type)", nameof (GetWithPublicMethods) + "()", + ProducedBy = ProducedBy.Analyzer)] + [ExpectedWarning ("IL2072", nameof (RequireAllTrue) + "(Type)", nameof (GetWithPublicFields) + "()")] + [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods) + "()", + ProducedBy = ProducedBy.Analyzer)] + [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields) + "()")] + public static void ExceptionFilter () { - return null; + Type t = GetWithPublicMethods (); + try { + t = GetWithPublicFields (); + } catch (Exception) when (RequireAllTrue (t)) { + RequireAll (t); + } } - [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] - public static Type GetWithPublicFields () + [ExpectedWarning ("IL2072", nameof (RequireAllTrue) + "(Type)", nameof (GetWithPublicFields) + "()")] + [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields) + "()")] + [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicMethods) + "()")] + [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields) + "()")] + + // Linker merges branches going forward. + [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods) + "()", + ProducedBy = ProducedBy.Trimmer)] + public static void ExceptionFilterStateChange () { - return null; + Type t = GetWithPublicMethods (); + try { + } catch (Exception) when (RequireAllTrue (t = GetWithPublicFields ())) { + RequireAll (t); + } finally { + RequireAll2 (t); + } } - [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicProperties)] - public static Type GetWithPublicProperties () + + [ExpectedWarning ("IL2072", nameof (RequireAllFalse) + "(Type)", nameof (GetWithPublicFields) + "()")] + [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields) + "()")] + + [ExpectedWarning ("IL2072", nameof (RequireAllTrue) + "(Type)", nameof (GetWithPublicProperties) + "()")] + [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicProperties) + "()")] + + [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicMethods) + "()")] + [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicFields) + "()")] + [ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicProperties) + "()")] + + [ExpectedWarning ("IL2072", nameof (RequireAllFalse2) + "(Type)", nameof (GetWithPublicMethods) + "()")] + [ExpectedWarning ("IL2072", nameof (RequireAllFalse2) + "(Type)", nameof (GetWithPublicFields) + "()")] + [ExpectedWarning ("IL2072", nameof (RequireAllFalse2) + "(Type)", nameof (GetWithPublicProperties) + "()")] + [ExpectedWarning ("IL2072", nameof (RequireAll4) + "(Type)", nameof (GetWithPublicMethods) + "()")] + [ExpectedWarning ("IL2072", nameof (RequireAll4) + "(Type)", nameof (GetWithPublicFields) + "()")] + [ExpectedWarning ("IL2072", nameof (RequireAll4) + "(Type)", nameof (GetWithPublicProperties) + "()")] + + [ExpectedWarning ("IL2072", nameof (RequireAll5) + "(Type)", nameof (GetWithPublicMethods) + "()")] + [ExpectedWarning ("IL2072", nameof (RequireAll5) + "(Type)", nameof (GetWithPublicFields) + "()")] + [ExpectedWarning ("IL2072", nameof (RequireAll5) + "(Type)", nameof (GetWithPublicProperties) + "()")] + + [ExpectedWarning ("IL2072", nameof (RequireAll6) + "(Type)", nameof (GetWithPublicMethods) + "()")] + [ExpectedWarning ("IL2072", nameof (RequireAll6) + "(Type)", nameof (GetWithPublicFields) + "()")] + [ExpectedWarning ("IL2072", nameof (RequireAll6) + "(Type)", nameof (GetWithPublicProperties) + "()")] + + // Linker merges branches going forward. + [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods) + "()", + ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicMethods) + "()", + ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields) + "()", + ProducedBy = ProducedBy.Trimmer)] + public static void ExceptionMultipleFilters () { - return null; + Type t = GetWithPublicMethods (); + try { + } catch (Exception) when (RequireAllFalse (t = GetWithPublicFields ())) { + RequireAll (t); + } catch (Exception) when (RequireAllTrue (t = GetWithPublicProperties ())) { + RequireAll2 (t); + } catch (Exception1) { + RequireAll3 (t); + } catch (Exception) when (RequireAllFalse2 (t)) { + RequireAll4 (t); + } catch { + RequireAll5 (t); + } + RequireAll6 (t); } - [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicEvents)] - public static Type GetWithPublicEvents () + + [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields))] + [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicProperties))] + + [ExpectedWarning ("IL2072", nameof (RequireAllTrue) + "(Type)", nameof (GetWithPublicMethods))] + [ExpectedWarning ("IL2072", nameof (RequireAllTrue) + "(Type)", nameof (GetWithPublicFields))] + [ExpectedWarning ("IL2072", nameof (RequireAllTrue) + "(Type)", nameof (GetWithPublicProperties))] + + [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicMethods))] + [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields))] + [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicProperties))] + + // Linker merges branches going forward. + [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods), + ProducedBy = ProducedBy.Trimmer)] + public static void ExceptionFilterWithBranch () { - return null; + Type t = GetWithPublicMethods (); + try { + } catch (Exception) when (string.Empty.Length == 0 ? (t = GetWithPublicFields ()) == null : (t = GetWithPublicProperties ()) == null) { + RequireAll (t); + } catch (Exception) when (RequireAllTrue (t)) { + } catch { + RequireAll2 (t); + } } - [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)] - public static Type GetWithPublicConstructors () + + [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods))] + [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields))] + [ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicProperties))] + + [ExpectedWarning ("IL2072", nameof (RequireAllTrue) + "(Type)", nameof (GetWithPublicMethods))] + [ExpectedWarning ("IL2072", nameof (RequireAllTrue) + "(Type)", nameof (GetWithPublicFields))] + [ExpectedWarning ("IL2072", nameof (RequireAllTrue) + "(Type)", nameof (GetWithPublicProperties))] + + [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicMethods))] + [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields))] + [ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicProperties))] + public static void ExceptionFilterWithException () { - return null; + Type t = GetWithPublicMethods (); + try { + } catch (Exception) when ((t = GetWithPublicFields ()) != null + ? (t = GetWithPublicProperties ()) == null + : (t = GetWithPublicProperties ()) == null) { + } catch (Exception1) { + // An exception thrown from the above filter could result in methods, fields, or properties here, + // even though a non-exceptional exit from the filter always leaves t with 'properties'. + RequireAll (t); + } catch (Exception2) when (RequireAllTrue (t)) { + // Same as above, with a filter. + RequireAll2 (t); + } } - public static void RequirePublicMethods ( - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] + public static bool RequireAllTrue ( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type) { + return true; } - public static void RequirePublicFields ( - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] + public static bool RequireAllFalse ( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type) { + return true; } - public static void RequirePublicProperties ( - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] + + public static bool RequireAllFalse2 ( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type) { + return true; } + [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] + public static Type GetWithPublicMethods () + { + return null; + } - public static void RequireFieldsAndProperties ( - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicProperties)] - Type type) + [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] + public static Type GetWithPublicFields () { + return null; + } + [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicProperties)] + public static Type GetWithPublicProperties () + { + return null; + } + [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicEvents)] + public static Type GetWithPublicEvents () + { + return null; + } + [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)] + public static Type GetWithPublicConstructors () + { + return null; } public static void RequireAll ( |