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-11-30 22:09:28 +0300
committerGitHub <noreply@github.com>2021-11-30 22:09:28 +0300
commitd8170a8f95a52267f0fc87d76eb97e724f13b3f7 (patch)
tree2c53bfed4a284c630b0806b51b00fb672bf3eb39 /test/Mono.Linker.Tests.Cases/DataFlow
parent888fed7b56fbef827be1cdedb018153643613459 (diff)
[DAM analyzer] Add support for properties and enable more tests (#2390)
The IOperation tree represents properties as IPropertyReferenceOperation, so we need to handle properties specially (whereas the linker sees calls to the getter/setter directly).
Diffstat (limited to 'test/Mono.Linker.Tests.Cases/DataFlow')
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/ApplyTypeAnnotations.cs6
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs8
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs15
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs46
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs34
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs120
6 files changed, 174 insertions, 55 deletions
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/ApplyTypeAnnotations.cs b/test/Mono.Linker.Tests.Cases/DataFlow/ApplyTypeAnnotations.cs
index 5863cf4a4..f02ea1cba 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/ApplyTypeAnnotations.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/ApplyTypeAnnotations.cs
@@ -50,6 +50,12 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
[Kept]
+ // Analyzer doesn't support intrinsics: https://github.com/dotnet/linker/issues/2374
+ [ExpectedWarning ("IL2026", "System.Type.GetType(String)",
+ ProducedBy = ProducedBy.Analyzer)]
+ // Analyzer doesn't track known types: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2072", "'type'", nameof (ApplyTypeAnnotations) + "." + nameof (RequireCombination) + "(Type)", "System.Type.GetType(String)",
+ ProducedBy = ProducedBy.Analyzer)]
static void TestFromTypeGetTypeOverConstant ()
{
RequireCombination (Type.GetType ("Mono.Linker.Tests.Cases.DataFlow.ApplyTypeAnnotations+FromTypeGetTypeOverConstantTestType"));
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs
index 6cb0409cf..69d4e7959 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs
@@ -40,14 +40,18 @@ namespace Mono.Linker.Tests.Cases.DataFlow
static Type s_typeWithPublicParameterlessConstructor;
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (ByRefDataflow), nameof (MethodWithRefParameter), new string[] { "Type&" }, messageCode: "IL2077")]
+ // Trimmer and analyzer use different formats for ref parameters: https://github.com/dotnet/linker/issues/2406
+ [ExpectedWarning ("IL2077", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(Type&)", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2077", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(ref Type)", ProducedBy = ProducedBy.Analyzer)]
public static void PassRefToField ()
{
MethodWithRefParameter (ref s_typeWithPublicParameterlessConstructor);
}
[Kept]
- [UnrecognizedReflectionAccessPattern (typeof (ByRefDataflow), nameof (MethodWithRefParameter), new string[] { "Type&" }, messageCode: "IL2067")]
+ // Trimmer and analyzer use different formats for ref parameters: https://github.com/dotnet/linker/issues/2406
+ [ExpectedWarning ("IL2067", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(Type&)", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2067", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(ref Type)", ProducedBy = ProducedBy.Analyzer)]
public static void PassRefToParameter (Type parameter)
{
MethodWithRefParameter (ref parameter);
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs b/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs
index 7bcfbc70c..858d40088 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs
@@ -99,6 +99,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
[Kept]
+ // Analyzer doesn't support intrinsics: https://github.com/dotnet/linker/issues/2374
+ [ExpectedWarning ("IL2072", "'type'", nameof (ComplexTypeHandling) + "." + nameof (RequirePublicMethods) + "(Type)", "System.Object.GetType()",
+ ProducedBy = ProducedBy.Analyzer)]
static void TestArrayGetTypeFromMethodParamHelper (ArrayGetTypeFromMethodParamElement[] p)
{
RequirePublicMethods (p.GetType ());
@@ -121,6 +124,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow
static ArrayGetTypeFromFieldElement[] _arrayGetTypeFromField;
[Kept]
+ // Analyzer doesn't support intrinsics: https://github.com/dotnet/linker/issues/2374
+ [ExpectedWarning ("IL2072", "'type'", nameof (ComplexTypeHandling) + "." + nameof (RequirePublicMethods) + "(Type)", "System.Object.GetType()",
+ ProducedBy = ProducedBy.Analyzer)]
static void TestArrayGetTypeFromField ()
{
RequirePublicMethods (_arrayGetTypeFromField.GetType ());
@@ -134,6 +140,12 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
[Kept]
+ // Analyzer doesn't support intrinsics: https://github.com/dotnet/linker/issues/2374
+ [ExpectedWarning ("IL2026", "System.Type.GetType(String)",
+ ProducedBy = ProducedBy.Analyzer)]
+ // Analyzer doesn't track known types: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2072", "'type'", nameof (ComplexTypeHandling) + "." + nameof (RequirePublicMethods) + "(Type)", "System.Type.GetType(String)",
+ ProducedBy = ProducedBy.Analyzer)]
static void TestArrayTypeGetType ()
{
RequirePublicMethods (Type.GetType ("Mono.Linker.Tests.Cases.DataFlow.ComplexTypeHandling+ArrayTypeGetTypeElement[]"));
@@ -148,6 +160,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
[Kept]
+ // Analyzer doesn't support intrinsics: https://github.com/dotnet/linker/issues/2374
+ [ExpectedWarning ("IL2026", "Activator.CreateInstance(String, String)",
+ ProducedBy = ProducedBy.Analyzer)]
static void TestArrayCreateInstanceByName ()
{
Activator.CreateInstance ("test", "Mono.Linker.Tests.Cases.DataFlow.ComplexTypeHandling+ArrayCreateInstanceByNameElement[]");
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs
index cb36d87a3..30b520ff7 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
@@ -43,7 +43,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow
static Type _staticTypeWithoutRequirements;
- [ExpectedWarning ("IL2097", nameof (_annotationOnWrongType))]
+ // TODO: warn about annotation on wrong type in analyzer: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2097", nameof (_annotationOnWrongType),
+ ProducedBy = ProducedBy.Trimmer)]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)]
static object _annotationOnWrongType;
@@ -58,18 +60,14 @@ namespace Mono.Linker.Tests.Cases.DataFlow
RequireNothing (_typeWithPublicParameterlessConstructor);
}
- [UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (_typeWithPublicParameterlessConstructor),
- messageCode: "IL2074", message: new string[] {
- nameof (GetUnkownType),
- nameof (_typeWithPublicParameterlessConstructor)
- })]
- [UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (_typeWithPublicParameterlessConstructor), messageCode: "IL2074")]
+ [ExpectedWarning ("IL2074", nameof (FieldDataFlow) + "." + nameof (_typeWithPublicParameterlessConstructor), nameof (GetUnknownType))]
+ [ExpectedWarning ("IL2074", nameof (FieldDataFlow) + "." + nameof (_typeWithPublicParameterlessConstructor), nameof (GetTypeWithNonPublicConstructors))]
private void WriteToInstanceField ()
{
_typeWithPublicParameterlessConstructor = GetTypeWithPublicParameterlessConstructor ();
_typeWithPublicParameterlessConstructor = GetTypeWithPublicConstructors ();
_typeWithPublicParameterlessConstructor = GetTypeWithNonPublicConstructors ();
- _typeWithPublicParameterlessConstructor = GetUnkownType ();
+ _typeWithPublicParameterlessConstructor = GetUnknownType ();
}
[UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2077")]
@@ -84,8 +82,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
RequireNothing (store._typeWithPublicParameterlessConstructor);
}
- [UnrecognizedReflectionAccessPattern (typeof (TypeStore), nameof (TypeStore._typeWithPublicParameterlessConstructor), messageCode: "IL2074")]
- [UnrecognizedReflectionAccessPattern (typeof (TypeStore), nameof (TypeStore._typeWithPublicParameterlessConstructor), messageCode: "IL2074")]
+ [ExpectedWarning ("IL2074", nameof (TypeStore) + "." + nameof (TypeStore._typeWithPublicParameterlessConstructor), nameof (GetUnknownType))]
+ [ExpectedWarning ("IL2074", nameof (TypeStore) + "." + nameof (TypeStore._typeWithPublicParameterlessConstructor), nameof (GetTypeWithNonPublicConstructors))]
private void WriteToInstanceFieldOnADifferentClass ()
{
var store = new TypeStore ();
@@ -93,7 +91,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
store._typeWithPublicParameterlessConstructor = GetTypeWithPublicParameterlessConstructor ();
store._typeWithPublicParameterlessConstructor = GetTypeWithPublicConstructors ();
store._typeWithPublicParameterlessConstructor = GetTypeWithNonPublicConstructors ();
- store._typeWithPublicParameterlessConstructor = GetUnkownType ();
+ store._typeWithPublicParameterlessConstructor = GetUnknownType ();
}
[UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2077")]
@@ -106,19 +104,15 @@ namespace Mono.Linker.Tests.Cases.DataFlow
RequireNothing (_staticTypeWithPublicParameterlessConstructor);
}
- [UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (_staticTypeWithPublicParameterlessConstructor), messageCode: "IL2074")]
- [UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (_staticTypeWithPublicParameterlessConstructor), messageCode: "IL2074")]
- [UnrecognizedReflectionAccessPattern (typeof (FieldDataFlow), nameof (_staticTypeWithPublicParameterlessConstructor),
- messageCode: "IL2079", message: new string[] {
- nameof(_staticTypeWithoutRequirements),
- nameof(_staticTypeWithPublicParameterlessConstructor)
- })]
+ [ExpectedWarning ("IL2074", nameof (FieldDataFlow) + "." + nameof (_staticTypeWithPublicParameterlessConstructor), nameof (GetUnknownType))]
+ [ExpectedWarning ("IL2074", nameof (FieldDataFlow) + "." + nameof (_staticTypeWithPublicParameterlessConstructor), nameof (GetTypeWithNonPublicConstructors))]
+ [ExpectedWarning ("IL2079", nameof (FieldDataFlow) + "." + nameof (_staticTypeWithPublicParameterlessConstructor), nameof (_staticTypeWithoutRequirements))]
private void WriteToStaticField ()
{
_staticTypeWithPublicParameterlessConstructor = GetTypeWithPublicParameterlessConstructor ();
_staticTypeWithPublicParameterlessConstructor = GetTypeWithPublicConstructors ();
_staticTypeWithPublicParameterlessConstructor = GetTypeWithNonPublicConstructors ();
- _staticTypeWithPublicParameterlessConstructor = GetUnkownType ();
+ _staticTypeWithPublicParameterlessConstructor = GetUnknownType ();
_staticTypeWithPublicParameterlessConstructor = _staticTypeWithoutRequirements;
}
@@ -132,17 +126,19 @@ namespace Mono.Linker.Tests.Cases.DataFlow
RequireNothing (TypeStore._staticTypeWithPublicParameterlessConstructor);
}
- [UnrecognizedReflectionAccessPattern (typeof (TypeStore), nameof (TypeStore._staticTypeWithPublicParameterlessConstructor), messageCode: "IL2074")]
- [UnrecognizedReflectionAccessPattern (typeof (TypeStore), nameof (TypeStore._staticTypeWithPublicParameterlessConstructor), messageCode: "IL2074")]
+ [ExpectedWarning ("IL2074", nameof (TypeStore) + "." + nameof (TypeStore._staticTypeWithPublicParameterlessConstructor), nameof (GetUnknownType))]
+ [ExpectedWarning ("IL2074", nameof (TypeStore) + "." + nameof (TypeStore._staticTypeWithPublicParameterlessConstructor), nameof (GetTypeWithNonPublicConstructors))]
private void WriteToStaticFieldOnADifferentClass ()
{
TypeStore._staticTypeWithPublicParameterlessConstructor = GetTypeWithPublicParameterlessConstructor ();
TypeStore._staticTypeWithPublicParameterlessConstructor = GetTypeWithPublicConstructors ();
TypeStore._staticTypeWithPublicParameterlessConstructor = GetTypeWithNonPublicConstructors ();
- TypeStore._staticTypeWithPublicParameterlessConstructor = GetUnkownType ();
+ TypeStore._staticTypeWithPublicParameterlessConstructor = GetUnknownType ();
}
- [UnrecognizedReflectionAccessPattern (typeof (TypeStore), nameof (TypeStore._staticTypeWithPublicParameterlessConstructor), messageCode: "IL2064", message: new string[] { nameof (TypeStore._staticTypeWithPublicParameterlessConstructor) })]
+ // TODO: warn about unknown types in analyzer: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2064", nameof (TypeStore) + "." + nameof (TypeStore._staticTypeWithPublicParameterlessConstructor),
+ ProducedBy = ProducedBy.Trimmer)]
private void WriteUnknownValue ()
{
var array = new object[1];
@@ -191,7 +187,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow
return null;
}
- private static Type GetUnkownType ()
+ private static Type GetUnknownType ()
{
return null;
}
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs
index 5ca8b3181..56c0844d4 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
@@ -92,9 +92,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow
t.GetMethod ("foo");
NonTypeType.StaticMethod ();
}
-
- [UnrecognizedReflectionAccessPattern (typeof (MethodThisDataFlowTypeTest), nameof (MethodThisDataFlowTypeTest.RequireThisNonPublicMethods), new Type[] { },
- messageCode: "IL2065", message: new string[] { nameof (MethodThisDataFlowTypeTest.RequireThisNonPublicMethods) })]
+ // Analyer doesn't warn about unknown values flowing into annotated locations
+ // https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2065", nameof (MethodThisDataFlowTypeTest) + "." + nameof (MethodThisDataFlowTypeTest.RequireThisNonPublicMethods), "'this'",
+ ProducedBy = ProducedBy.Trimmer)]
static void TestUnknownThis ()
{
var array = new object[1];
@@ -143,14 +144,18 @@ namespace Mono.Linker.Tests.Cases.DataFlow
class NonTypeType
{
- [ExpectedWarning ("IL2041")]
+ // Analyzer doesn't warn about annotations on unsupported types:
+ // https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2041", ProducedBy = ProducedBy.Trimmer)]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
public MethodInfo GetMethod (string name)
{
return null;
}
- [ExpectedWarning ("IL2041")]
+ // Analyzer doesn't warn about annotations on unsupported types:
+ // https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2041", ProducedBy = ProducedBy.Trimmer)]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
public static void StaticMethod ()
{
@@ -164,10 +169,9 @@ namespace System
class MethodThisDataFlowTypeTest : TestSystemTypeBase
{
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
- [UnrecognizedReflectionAccessPattern (typeof (MethodThisDataFlowTypeTest), nameof (RequireNonPublicMethods), new Type[] { typeof (Type) },
- messageCode: "IL2082", message: new string[] {
- "'type' argument ", "in call to 'System.MethodThisDataFlowTypeTest.RequireNonPublicMethods(Type)'",
- "implicit 'this' argument of method 'System.MethodThisDataFlowTypeTest.RequireThisPublicMethods()'" })]
+ [ExpectedWarning ("IL2082", nameof (MethodThisDataFlowTypeTest) + "." + nameof (RequireNonPublicMethods) + "(Type)",
+ "'type' argument ", "in call to 'System.MethodThisDataFlowTypeTest.RequireNonPublicMethods(Type)'",
+ "implicit 'this' argument of method 'System.MethodThisDataFlowTypeTest.RequireThisPublicMethods()'")]
public void RequireThisPublicMethods ()
{
RequirePublicMethods (this);
@@ -175,8 +179,7 @@ namespace System
}
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicMethods)]
- [UnrecognizedReflectionAccessPattern (typeof (MethodThisDataFlowTypeTest), nameof (RequirePublicMethods), new Type[] { typeof (Type) },
- messageCode: "IL2082")]
+ [ExpectedWarning ("IL2082", nameof (MethodThisDataFlowTypeTest) + "." + nameof (RequirePublicMethods) + "(Type)")]
public void RequireThisNonPublicMethods ()
{
RequirePublicMethods (this);
@@ -198,11 +201,8 @@ namespace System
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
Type _requiresPublicConstructors;
- [UnrecognizedReflectionAccessPattern (typeof (MethodThisDataFlowTypeTest), nameof (_requiresPublicConstructors),
- messageCode: "IL2084", message: new string[] {
- nameof (PropagateToField),
- nameof (_requiresPublicConstructors)
- })]
+ [ExpectedWarning ("IL2084", nameof (MethodThisDataFlowTypeTest) + "." + nameof (_requiresPublicConstructors),
+ nameof (PropagateToField))]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
public void PropagateToField ()
{
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs
index d1f6d57eb..685b6a296 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs
@@ -42,7 +42,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
static Type StaticPropertyWithPublicConstructor { get; set; }
- [ExpectedWarning ("IL2099", nameof (PropertyWithUnsupportedType))]
+ // Analyzer doesn't warn about annotations on unsupported types
+ // https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2099", nameof (PropertyWithUnsupportedType), ProducedBy = ProducedBy.Trimmer)]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)]
static object PropertyWithUnsupportedType { get; set; }
@@ -110,8 +112,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow
return _fieldWithPublicConstructors;
}
- [UnrecognizedReflectionAccessPattern (typeof (PropertyDataFlow), nameof (_fieldWithPublicConstructors),
- messageCode: "IL2069", message: new string[] { "value", nameof (PropertyPublicParameterlessConstructorWithExplicitAccessors) + ".set", nameof (_fieldWithPublicConstructors) })]
+ [ExpectedWarning ("IL2069", nameof (PropertyDataFlow) + "." + nameof (_fieldWithPublicConstructors),
+ "'value'",
+ nameof (PropertyPublicParameterlessConstructorWithExplicitAccessors) + ".set")]
[param: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
set {
_fieldWithPublicConstructors = value;
@@ -129,7 +132,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow
return _fieldWithPublicConstructors;
}
- [UnrecognizedReflectionAccessPattern (typeof (PropertyDataFlow), nameof (_fieldWithPublicConstructors), messageCode: "IL2069")]
+ [ExpectedWarning ("IL2069", nameof (PropertyDataFlow) + "." + nameof (_fieldWithPublicConstructors),
+ "'value'",
+ nameof (PropertyNonPublicConstructorsWithExplicitAccessors) + ".set")]
[param: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicConstructors)]
set {
_fieldWithPublicConstructors = value;
@@ -145,6 +150,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
instance.TestInstancePropertyWithStaticField ();
instance.TestPropertyWithDifferentBackingFields ();
instance.TestPropertyWithExistingAttributes ();
+ instance.TestPropertyWithConflictingAttributes ();
+ instance.TestPropertyWithConflictingNoneAttributes ();
instance.TestPropertyWithIndexerWithMatchingAnnotations (null);
instance.TestPropertyWithIndexerWithoutMatchingAnnotations (null);
}
@@ -185,6 +192,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
[RecognizedReflectionAccessPattern]
+ // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2077", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors) + "(Type)",
+ nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWhichLooksLikeCompilerGenerated_Field),
+ ProducedBy = ProducedBy.Analyzer)]
public void TestPropertyWhichLooksLikeCompilerGenerated ()
{
// If the property was correctly recognized both the property getter and the backing field should get the annotation.
@@ -197,6 +208,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
static Type PropertyWhichLooksLikeCompilerGenerated {
+ // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2078", nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWhichLooksLikeCompilerGenerated) + ".get",
+ nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWhichLooksLikeCompilerGenerated_Field),
+ ProducedBy = ProducedBy.Analyzer)]
get {
return PropertyWhichLooksLikeCompilerGenerated_Field;
}
@@ -235,8 +250,14 @@ namespace Mono.Linker.Tests.Cases.DataFlow
[CompilerGenerated]
private Type PropertyWithDifferentBackingFields_SetterField;
+ // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273
[ExpectedWarning ("IL2042",
- "Mono.Linker.Tests.Cases.DataFlow.PropertyDataFlow.TestAutomaticPropagationType.PropertyWithDifferentBackingFields")]
+ "Mono.Linker.Tests.Cases.DataFlow.PropertyDataFlow.TestAutomaticPropagationType.PropertyWithDifferentBackingFields",
+ ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2078",
+ nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWithDifferentBackingFields) + ".get",
+ "Type",
+ ProducedBy = ProducedBy.Analyzer)]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
Type PropertyWithDifferentBackingFields {
get {
@@ -254,22 +275,95 @@ namespace Mono.Linker.Tests.Cases.DataFlow
PropertyWithExistingAttributes = null;
}
- [ExpectedWarning ("IL2056", "PropertyWithExistingAttributes", "PropertyWithExistingAttributes_Field")]
+ // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2056", "PropertyWithExistingAttributes", "PropertyWithExistingAttributes_Field",
+ ProducedBy = ProducedBy.Trimmer)]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
[CompilerGenerated]
Type PropertyWithExistingAttributes_Field;
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
Type PropertyWithExistingAttributes {
- [ExpectedWarning ("IL2043", "PropertyWithExistingAttributes", "PropertyWithExistingAttributes.get")]
+ // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2043", "PropertyWithExistingAttributes", "PropertyWithExistingAttributes.get",
+ ProducedBy = ProducedBy.Trimmer)]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
get { return PropertyWithExistingAttributes_Field; }
- [ExpectedWarning ("IL2043", "PropertyWithExistingAttributes", "PropertyWithExistingAttributes.set")]
+ // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2043", "PropertyWithExistingAttributes", "PropertyWithExistingAttributes.set",
+ ProducedBy = ProducedBy.Trimmer)]
[param: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
set { PropertyWithExistingAttributes_Field = value; }
}
+ // When the property annotation conflicts with the getter/setter annotation,
+ // we issue a warning (IL2043 below) but respect the getter/setter annotations.
+ [ExpectedWarning ("IL2072", nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWithConflictingAttributes) + ".get",
+ nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors) + "(Type)")]
+ [ExpectedWarning ("IL2072", nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWithConflictingAttributes) + ".set",
+ nameof (PropertyDataFlow) + "." + nameof (GetTypeWithPublicConstructors) + "()")]
+ public void TestPropertyWithConflictingAttributes ()
+ {
+ PropertyWithConflictingAttributes.RequiresPublicConstructors ();
+ PropertyWithConflictingAttributes.RequiresNonPublicConstructors ();
+ PropertyWithConflictingAttributes = GetTypeWithPublicConstructors ();
+ PropertyWithConflictingAttributes = GetTypeWithNonPublicConstructors ();
+ }
+
+ // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2056", "PropertyWithConflictingAttributes", "PropertyWithConflictingAttributes_Field",
+ ProducedBy = ProducedBy.Trimmer)]
+ [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicConstructors)]
+ [CompilerGenerated]
+ Type PropertyWithConflictingAttributes_Field;
+
+ [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
+ Type PropertyWithConflictingAttributes {
+ // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2043", "PropertyWithConflictingAttributes", "PropertyWithConflictingAttributes.get",
+ ProducedBy = ProducedBy.Trimmer)]
+ [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicConstructors)]
+ get { return PropertyWithConflictingAttributes_Field; }
+
+ // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2043", "PropertyWithConflictingAttributes", "PropertyWithConflictingAttributes.set",
+ ProducedBy = ProducedBy.Trimmer)]
+ [param: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicConstructors)]
+ set { PropertyWithConflictingAttributes_Field = value; }
+ }
+
+ // When the property annotation is DAMT.None and this conflicts with the getter/setter annotations,
+ // we don't produce a warning about the conflict, and just respect the property annotations.
+ [ExpectedWarning ("IL2072", nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWithConflictingNoneAttributes) + ".get",
+ nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors) + "(Type)")]
+ [ExpectedWarning ("IL2072", nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWithConflictingNoneAttributes) + ".set",
+ nameof (PropertyDataFlow) + "." + nameof (GetTypeWithNonPublicConstructors) + "()")]
+ public void TestPropertyWithConflictingNoneAttributes ()
+ {
+ PropertyWithConflictingNoneAttributes.RequiresPublicConstructors ();
+ PropertyWithConflictingNoneAttributes.RequiresNonPublicConstructors ();
+ PropertyWithConflictingNoneAttributes = GetTypeWithPublicConstructors ();
+ PropertyWithConflictingNoneAttributes = GetTypeWithNonPublicConstructors ();
+ }
+
+ [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.None)]
+ [CompilerGenerated]
+ Type PropertyWithConflictingNoneAttributes_Field;
+
+ [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
+ Type PropertyWithConflictingNoneAttributes {
+ // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2078", nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWithConflictingNoneAttributes) + ".get",
+ nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWithConflictingNoneAttributes_Field),
+ ProducedBy = ProducedBy.Analyzer)]
+ [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.None)]
+ get { return PropertyWithConflictingNoneAttributes_Field; }
+
+ [param: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.None)]
+ set { PropertyWithConflictingNoneAttributes_Field = value; }
+ }
+
[RecognizedReflectionAccessPattern]
public void TestPropertyWithIndexerWithMatchingAnnotations ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)] Type myType)
{
@@ -278,8 +372,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow
propclass[1].RequiresPublicConstructors ();
}
- [UnrecognizedReflectionAccessPattern (typeof (PropertyWithIndexer), "Item.set", new Type[] { typeof (Type) }, messageCode: "IL2067")]
- [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), "RequiresNonPublicConstructors", new Type[] { typeof (Type) }, messageCode: "IL2072")]
+ // Trimmer and analyzer handle formatting of indexers differently.
+ [ExpectedWarning ("IL2067", nameof (PropertyWithIndexer) + ".Item.set", ProducedBy = ProducedBy.Trimmer)]
+ [ExpectedWarning ("IL2067", nameof (PropertyWithIndexer) + ".this[Int32].set", ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors) + "(Type)")]
[LogDoesNotContain ("'Value passed to parameter 'index' of method 'Mono.Linker.Tests.Cases.DataFlow.PropertyDataFlow.TestAutomaticPropagationType.PropertyWithIndexer.Item.set'")]
public void TestPropertyWithIndexerWithoutMatchingAnnotations (Type myType)
{
@@ -295,7 +391,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)]
public Type this[int index] {
- [ExpectedWarning ("IL2063", "PropertyWithIndexer.Item.get")]
+ // TODO: warn about unknown types in analyzer: https://github.com/dotnet/linker/issues/2273
+ [ExpectedWarning ("IL2063", "PropertyWithIndexer.Item.get",
+ ProducedBy = ProducedBy.Trimmer)]
get => Property_Field[index];
set => Property_Field[index] = value;
}