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:
authorVitek Karas <vitek.karas@microsoft.com>2020-08-18 21:50:07 +0300
committerGitHub <noreply@github.com>2020-08-18 21:50:07 +0300
commit7eae638feafc7dc766f51f440e760220707a87ad (patch)
tree7e60a801398517ba2bd8255e40230334678e9957 /test/Mono.Linker.Tests.Cases/DataFlow
parent01574d3be1e27cf414fee8fe834e2e49f7a50173 (diff)
Warn when DynamicallyAccessedMembersAttribute is used on a member of unsupported type (#1431)
`DynamicallyAccessedMembersAttribute` is only supported on items of type `System.Type` or `System.String` (and derived classes) otherwise linker will ignore it. When it happens it's very likely not intentional and so linker should warn about it. Since it only affects analysis results, these are marked as TrimAnalysis.
Diffstat (limited to 'test/Mono.Linker.Tests.Cases/DataFlow')
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs6
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs6
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs4
3 files changed, 16 insertions, 0 deletions
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs
index 21b96b9b8..ef8719c11 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs
@@ -32,6 +32,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
instance.WriteToStaticFieldOnADifferentClass ();
instance.WriteUnknownValue ();
+
+ _ = _annotationOnWrongType;
}
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
@@ -42,6 +44,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow
static Type _staticTypeWithoutRequirements;
+ [ExpectedWarning ("IL2097", nameof (_annotationOnWrongType))]
+ [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)]
+ static object _annotationOnWrongType;
+
[UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) },
messageCode: "IL2077", message: new string[] { "_typeWithPublicParameterlessConstructor", "type", "RequirePublicConstructors(Type)" })]
[UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (RequireNonPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2077")]
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs
index ce2c49047..221d50721 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs
@@ -35,6 +35,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
instance.UnknownValueToUnAnnotatedParameterOnInterestingMethod ();
instance.WriteToParameterOnInstanceMethod (null);
instance.LongWriteToParameterOnInstanceMethod (0, 0, 0, 0, null);
+ instance.UnsupportedParameterType (null);
}
// Validate the error message when annotated parameter is passed to another annotated parameter
@@ -183,6 +184,11 @@ namespace Mono.Linker.Tests.Cases.DataFlow
RequirePublicParameterlessConstructorAndNothing (typeof (TestType), this.GetType ());
}
+ [ExpectedWarning ("IL2098", "p1", nameof (UnsupportedParameterType))]
+ private void UnsupportedParameterType ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] object p1)
+ {
+ }
+
private static void RequirePublicParameterlessConstructor (
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
Type type)
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs
index 2d7e7363b..72acb4ec1 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs
@@ -43,6 +43,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
static Type StaticPropertyWithPublicConstructor { get; set; }
+ [ExpectedWarning ("IL2099", nameof (PropertyWithUnsupportedType))]
+ [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)]
+ static object PropertyWithUnsupportedType { get; set; }
+
[UnrecognizedReflectionAccessPattern (typeof (PropertyDataFlow), nameof (RequireNonPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")]
private void ReadFromInstanceProperty ()
{