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:
authorSven Boemer <sbomer@gmail.com>2021-08-10 20:10:20 +0300
committerGitHub <noreply@github.com>2021-08-10 20:10:20 +0300
commitd8b94bd244f9239ef394817e2bd9a37ec1bae838 (patch)
tree0d74ea5c59ba7f18c121b60eb530d4f7a41cc156 /test/Mono.Linker.Tests.Cases/DataFlow
parente21bb44ca909d33c18acf3ed0b68f94a413351a5 (diff)
Fix warnings for DAM.All (#2191)
* Fix warnings for DAM.All Fixes https://github.com/mono/linker/issues/2159 * Add tests * PR feedback - Remove unnecessary helper * Avoid redundant DAM warnings for base members * PR feedback - Resolve -> TryResolve - Avoid nested yield returns - Testcases with base instantiated over self for generic parameter with requirements
Diffstat (limited to 'test/Mono.Linker.Tests.Cases/DataFlow')
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/AnnotatedMembersAccessedViaReflection.cs97
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs20
2 files changed, 117 insertions, 0 deletions
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/AnnotatedMembersAccessedViaReflection.cs b/test/Mono.Linker.Tests.Cases/DataFlow/AnnotatedMembersAccessedViaReflection.cs
index f94b9a458..4b626431f 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/AnnotatedMembersAccessedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/AnnotatedMembersAccessedViaReflection.cs
@@ -84,6 +84,38 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (AnnotatedField).RequiresPublicFields ();
}
+ class NestedType
+ {
+ [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
+ public static Type _annotatedField;
+ }
+
+ [ExpectedWarning ("IL2110", nameof (_annotatedField))]
+ [ExpectedWarning ("IL2026", "test")]
+ static void DynamicallyAccessedMembersAll1 ()
+ {
+ typeof (AnnotatedField).RequiresAll ();
+ }
+
+ [ExpectedWarning ("IL2110", nameof (_annotatedField))]
+ [ExpectedWarning ("IL2026", "test")]
+ static void DynamicallyAccessedMembersAll2 ()
+ {
+ typeof (AnnotatedField).RequiresAll ();
+ }
+
+ [ExpectedWarning ("IL2110", nameof (NestedType), nameof (NestedType._annotatedField))]
+ static void DynamicallyAccessedMembersNestedTypes1 ()
+ {
+ typeof (AnnotatedField).RequiresNonPublicNestedTypes ();
+ }
+
+ [ExpectedWarning ("IL2110", nameof (NestedType), nameof (NestedType._annotatedField))]
+ static void DynamicallyAccessedMembersNestedTypes2 ()
+ {
+ typeof (AnnotatedField).RequiresNonPublicNestedTypes ();
+ }
+
[UnconditionalSuppressMessage ("test", "IL2026")]
public static void Test ()
{
@@ -95,6 +127,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow
DynamicDependencyByName ();
DynamicallyAccessedMembers ();
DynamicallyAccessedMembersSuppressedByRUC ();
+ DynamicallyAccessedMembersAll1 ();
+ DynamicallyAccessedMembersAll2 ();
+ DynamicallyAccessedMembersNestedTypes1 ();
+ DynamicallyAccessedMembersNestedTypes2 ();
}
}
@@ -177,6 +213,22 @@ namespace Mono.Linker.Tests.Cases.DataFlow
var _ = new Action<Type> (instance.AnnotatedMethod);
}
+ [ExpectedWarning ("IL2111", nameof (MethodWithSingleAnnotatedParameter))]
+ [ExpectedWarning ("IL2026", "test")]
+ [ExpectedWarning ("IL2111", nameof (IWithAnnotatedMethod.AnnotatedMethod))]
+ static void DynamicallyAccessedMembersAll1 ()
+ {
+ typeof (AnnotatedMethodParameters).RequiresAll ();
+ }
+
+ [ExpectedWarning ("IL2111", nameof (MethodWithSingleAnnotatedParameter))]
+ [ExpectedWarning ("IL2026", "test")]
+ [ExpectedWarning ("IL2111", nameof (IWithAnnotatedMethod.AnnotatedMethod))]
+ static void DynamicallyAccessedMembersAll2 ()
+ {
+ typeof (AnnotatedMethodParameters).RequiresAll ();
+ }
+
[UnconditionalSuppressMessage ("test", "IL2026")]
public static void Test ()
{
@@ -189,6 +241,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
DynamicallyAccessedMembersSuppressedByRUC ();
Ldftn ();
Ldvirtftn ();
+ DynamicallyAccessedMembersAll1 ();
+ DynamicallyAccessedMembersAll2 ();
}
}
@@ -395,6 +449,24 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (AnnotatedProperty).RequiresPublicProperties ();
}
+ [ExpectedWarning ("IL2111", nameof (PropertyWithAnnotation) + ".set")]
+ [ExpectedWarning ("IL2026", "test")]
+ [ExpectedWarning ("IL2111", nameof (VirtualPropertyWithAnnotationGetterOnly) + ".get")]
+ [UnconditionalSuppressMessage ("Test", "IL2110", Justification = "Suppress warning about backing field of PropertyWithAnnotation")]
+ static void DynamicallyAccessedMembersAll1 ()
+ {
+ typeof (AnnotatedProperty).RequiresAll ();
+ }
+
+ [ExpectedWarning ("IL2111", nameof (PropertyWithAnnotation) + ".set")]
+ [ExpectedWarning ("IL2026", "test")]
+ [ExpectedWarning ("IL2111", nameof (VirtualPropertyWithAnnotationGetterOnly) + ".get")]
+ [UnconditionalSuppressMessage ("Test", "IL2110", Justification = "Suppress warning about backing field of PropertyWithAnnotation")]
+ static void DynamicallyAccessedMembersAll2 ()
+ {
+ typeof (AnnotatedProperty).RequiresAll ();
+ }
+
[UnconditionalSuppressMessage ("test", "IL2026")]
public static void Test ()
{
@@ -410,6 +482,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
DynamicDependencySuppressedByRUC ();
DynamicallyAccessedMembers ();
DynamicallyAccessedMembersSuppressedByRUC ();
+ DynamicallyAccessedMembersAll1 ();
+ DynamicallyAccessedMembersAll2 ();
}
}
@@ -446,12 +520,19 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (AnnotatedGenerics).GetMethod (nameof (GenericWithAnnotation)).MakeGenericMethod (type);
}
+ // Like above, no warning expected
+ static void DynamicallyAccessedMembersAll ()
+ {
+ typeof (AnnotatedGenerics).RequiresAll ();
+ }
+
public static void Test ()
{
ReflectionOnly ();
DynamicDependency ();
DynamicallyAccessedMembers ();
InstantiateGeneric ();
+ DynamicallyAccessedMembersAll ();
}
}
@@ -499,6 +580,20 @@ namespace Mono.Linker.Tests.Cases.DataFlow
typeof (AnnotationOnGenerics).RequiresPublicMethods ();
}
+ [ExpectedWarning ("IL2111", nameof (GenericMethodWithAnnotation))]
+ [ExpectedWarning ("IL2111", "GenericWithAnnotatedMethod", "AnnotatedMethod")]
+ static void DynamicallyAccessedMembersAll1 ()
+ {
+ typeof (AnnotationOnGenerics).RequiresAll ();
+ }
+
+ [ExpectedWarning ("IL2111", nameof (GenericMethodWithAnnotation))]
+ [ExpectedWarning ("IL2111", "GenericWithAnnotatedMethod", "AnnotatedMethod")]
+ static void DynamicallyAccessedMembersAll2 ()
+ {
+ typeof (AnnotationOnGenerics).RequiresAll ();
+ }
+
public static void Test ()
{
GenericTypeWithStaticMethodViaLdftn ();
@@ -506,6 +601,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
GenericMethodWithAnnotationDirectCall ();
GenericMethodWithAnnotationViaLdftn ();
GenericMethodDynamicallyAccessedMembers ();
+ DynamicallyAccessedMembersAll1 ();
+ DynamicallyAccessedMembersAll2 ();
}
}
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs
index 09de0a015..1665c1abd 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/GenericParameterDataFlow.cs
@@ -243,6 +243,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
static void TestBaseTypeGenericRequirements ()
{
new DerivedTypeWithInstantiatedGenericOnBase ();
+ new DerivedTypeWithInstantiationOverSelfOnBase ();
new DerivedTypeWithOpenGenericOnBase<TestType> ();
new DerivedTypeWithOpenGenericOnBaseWithRequirements<TestType> ();
}
@@ -261,6 +262,15 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
+ class GenericBaseTypeWithRequiresAll<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] T>
+ {
+ }
+
+ [RecognizedReflectionAccessPattern]
+ class DerivedTypeWithInstantiationOverSelfOnBase : GenericBaseTypeWithRequirements<DerivedTypeWithInstantiationOverSelfOnBase>
+ {
+ }
+
[UnrecognizedReflectionAccessPattern (typeof (GenericBaseTypeWithRequirements<>), "T", messageCode: "IL2091")]
class DerivedTypeWithOpenGenericOnBase<T> : GenericBaseTypeWithRequirements<T>
{
@@ -277,6 +287,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
static void TestInterfaceTypeGenericRequirements ()
{
IGenericInterfaceTypeWithRequirements<TestType> instance = new InterfaceImplementationTypeWithInstantiatedGenericOnBase ();
+ new InterfaceImplementationTypeWithInstantiationOverSelfOnBase ();
new InterfaceImplementationTypeWithOpenGenericOnBase<TestType> ();
new InterfaceImplementationTypeWithOpenGenericOnBaseWithRequirements<TestType> ();
}
@@ -290,6 +301,15 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
}
+ interface IGenericInterfaceTypeWithRequiresAll<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] T>
+ {
+ }
+
+ [RecognizedReflectionAccessPattern]
+ class InterfaceImplementationTypeWithInstantiationOverSelfOnBase : IGenericInterfaceTypeWithRequiresAll<InterfaceImplementationTypeWithInstantiationOverSelfOnBase>
+ {
+ }
+
[UnrecognizedReflectionAccessPattern (typeof (IGenericInterfaceTypeWithRequirements<>), "T", messageCode: "IL2091")]
class InterfaceImplementationTypeWithOpenGenericOnBase<T> : IGenericInterfaceTypeWithRequirements<T>
{