diff options
Diffstat (limited to 'test/Mono.Linker.Tests.Cases/DataFlow/CompilerGeneratedCodeDataflow.cs')
-rw-r--r-- | test/Mono.Linker.Tests.Cases/DataFlow/CompilerGeneratedCodeDataflow.cs | 59 |
1 files changed, 51 insertions, 8 deletions
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/CompilerGeneratedCodeDataflow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/CompilerGeneratedCodeDataflow.cs index 73d160de7..6129eaaeb 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/CompilerGeneratedCodeDataflow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/CompilerGeneratedCodeDataflow.cs @@ -311,7 +311,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow void LocalFunction () => t.RequiresAll (); } - public static void ReadCapturedParameter (Type tParameter) + public static void ReadCapturedParameter (Type tParameter = null) { LocalFunction (); @@ -319,15 +319,35 @@ namespace Mono.Linker.Tests.Cases.DataFlow void LocalFunction () => tParameter.RequiresAll (); } - public static void ReadCapturedParameterAfterWrite (Type tParameter) + public static void ReadCapturedAnnotatedParameter ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type tParameter = null) + { + LocalFunction (); + + [ExpectedWarning ("IL2067", nameof (ReadCapturedAnnotatedParameter), "tParameter", nameof (DataFlowTypeExtensions.RequiresAll))] + void LocalFunction () => tParameter.RequiresAll (); + } + + public static void ReadCapturedParameterAfterWrite (Type tParameter = null) { tParameter = GetWithPublicMethods (); LocalFunction (); + // We produce dataflow warnings for the unknown parameter even though it has been overwritten + // with a value that satisfies the requirement. [ExpectedWarning ("IL2067", "tParameter", nameof (DataFlowTypeExtensions.RequiresPublicMethods))] void LocalFunction () => tParameter.RequiresPublicMethods (); } + [ExpectedWarning ("IL2072", "tParameter", nameof (GetWithPublicFields), ProducedBy = ProducedBy.Analyzer)] + public static void ReadCapturedParameterAfterWriteMismatch ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type tParameter = null) + { + tParameter = GetWithPublicFields (); + LocalFunction (); + + [ExpectedWarning ("IL2067", "tParameter", nameof (DataFlowTypeExtensions.RequiresPublicFields))] + void LocalFunction () => tParameter.RequiresPublicFields (); + } + [ExpectedWarning ("IL2072", nameof (GetWithPublicFields), nameof (DataFlowTypeExtensions.RequiresAll))] static void ReadCapturedVariableWithUnhoistedLocals () { @@ -363,8 +383,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow ReadCapturedVariableInMultipleFunctions (); ReadCapturedVariableInCallGraphCycle (); ReadCapturedVariableWithBackwardsBranch (); - ReadCapturedParameter (null); - ReadCapturedParameterAfterWrite (null); + ReadCapturedParameter (); + ReadCapturedAnnotatedParameter (); + ReadCapturedParameterAfterWrite (); + ReadCapturedParameterAfterWriteMismatch (); ReadCapturedVariableWithUnhoistedLocals (); WriteCapturedVariable (); } @@ -416,7 +438,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow lambda (); } - public static void ReadCapturedParameter (Type tParameter) + public static void ReadCapturedParameter (Type tParameter = null) { var lambda = [ExpectedWarning ("IL2067", nameof (ReadCapturedParameter), "tParameter", nameof (DataFlowTypeExtensions.RequiresAll))] @@ -425,7 +447,16 @@ namespace Mono.Linker.Tests.Cases.DataFlow lambda (); } - public static void ReadCapturedParameterAfterWrite (Type tParameter) + public static void ReadCapturedAnnotatedParameter ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type tParameter = null) + { + var lambda = + [ExpectedWarning ("IL2067", nameof (ReadCapturedAnnotatedParameter), "tParameter", nameof (DataFlowTypeExtensions.RequiresAll))] + () => tParameter.RequiresAll (); + + lambda (); + } + + public static void ReadCapturedParameterAfterWrite (Type tParameter = null) { tParameter = GetWithPublicMethods (); var lambda = @@ -436,6 +467,16 @@ namespace Mono.Linker.Tests.Cases.DataFlow lambda (); } + [ExpectedWarning ("IL2072", "tParameter", nameof (GetWithPublicFields), ProducedBy = ProducedBy.Analyzer)] + public static void ReadCapturedParameterAfterWriteMismatch ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type tParameter = null) + { + tParameter = GetWithPublicFields (); + var lambda = + [ExpectedWarning ("IL2067", "tParameter", nameof (DataFlowTypeExtensions.RequiresPublicFields))] + () => tParameter.RequiresPublicFields (); + lambda (); + } + [ExpectedWarning ("IL2072", nameof (GetWithPublicFields), nameof (DataFlowTypeExtensions.RequiresAll))] static void ReadCapturedVariableWithUnhoistedLocals () { @@ -465,8 +506,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow WarningsInBodyUnused (); ReadCapturedVariable (); ReadCapturedVariableAfterWriteAfterDefinition (); - ReadCapturedParameter (null); - ReadCapturedParameterAfterWrite (null); + ReadCapturedParameter (); + ReadCapturedAnnotatedParameter (); + ReadCapturedParameterAfterWrite (); + ReadCapturedParameterAfterWriteMismatch (); ReadCapturedVariableWithUnhoistedLocals (); WriteCapturedVariable (); } |