Skip to content

Commit 2e5ba55

Browse files
committed
PR feedback
- Clean up some test attributes - Add test with DAM field on annotated PublicMethods type - Add link to issue about duplicate warnings Also use replace DAMT with DAM in tests.
1 parent 17886e9 commit 2e5ba55

File tree

1 file changed

+40
-25
lines changed

1 file changed

+40
-25
lines changed

test/Mono.Linker.Tests.Cases/Reflection/TypeHierarchyReflectionWarnings.cs

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public static void Main ()
3434

3535
// Instantiate this type just so its property getters are considered reachable
3636
var b = new DerivedFromAnnotatedDerivedFromBase ();
37+
38+
// Check that this field doesn't produce a warning even if it is kept
39+
// for some non-reflection access.
40+
var f = AnnotatedPublicMethods.DAMField;
3741
}
3842

3943
[Kept]
@@ -68,8 +72,8 @@ class AnnotatedAll
6872
[Kept]
6973
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
7074
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
71-
[ExpectedWarning ("IL2114", nameof (AnnotatedAll), nameof (DAMTField))]
72-
public Type DAMTField;
75+
[ExpectedWarning ("IL2114", nameof (AnnotatedAll), nameof (DAMField))]
76+
public Type DAMField;
7377

7478
[Kept]
7579
[KeptAttributeAttribute (typeof (RequiresUnreferencedCodeAttribute))]
@@ -78,8 +82,8 @@ class AnnotatedAll
7882
public void RUCMethod () { }
7983

8084
[Kept]
81-
[ExpectedWarning ("IL2114", nameof (AnnotatedAll), nameof (DAMTMethod))]
82-
public void DAMTMethod (
85+
[ExpectedWarning ("IL2114", nameof (AnnotatedAll), nameof (DAMMethod))]
86+
public void DAMMethod (
8387
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
8488
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
8589
Type t
@@ -98,9 +102,19 @@ class AnnotatedPublicMethods
98102
[RequiresUnreferencedCode ("--RUC on AnnotatedPublicMethods.RUCMethod--")]
99103
public void RUCMethod () { }
100104

105+
// No warning for members not selected by the type's annotation
106+
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
107+
public static Type UnusedDAMField;
108+
109+
// No warning for members not selected by the type's annotation, even if field is referenced statically
110+
[Kept]
111+
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
112+
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
113+
public static Type DAMField;
114+
101115
[Kept]
102-
[ExpectedWarning ("IL2114", nameof (AnnotatedPublicMethods), nameof (DAMTMethod))]
103-
public void DAMTMethod (
116+
[ExpectedWarning ("IL2114", nameof (AnnotatedPublicMethods), nameof (DAMMethod))]
117+
public void DAMMethod (
104118
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
105119
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
106120
Type t
@@ -116,13 +130,13 @@ class AnnotatedPublicFields
116130
[Kept]
117131
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
118132
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
119-
[ExpectedWarning ("IL2114", nameof (AnnotatedPublicFields), nameof (DAMTField))]
120-
public Type DAMTField;
133+
[ExpectedWarning ("IL2114", nameof (AnnotatedPublicFields), nameof (DAMField))]
134+
public Type DAMField;
121135

122136
}
123137

124138
[Kept]
125-
[KeptMember ("get_DAMTProperty()")]
139+
[KeptMember ("get_DAMProperty()")]
126140
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
127141
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicProperties)]
128142
class AnnotatedPublicProperties
@@ -131,9 +145,9 @@ class AnnotatedPublicProperties
131145
[KeptBackingField]
132146
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
133147
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
134-
public static string DAMTProperty {
148+
public static string DAMProperty {
135149
// Property access reports warnings on getter/setter
136-
[ExpectedWarning ("IL2114", nameof (AnnotatedPublicProperties), nameof (DAMTProperty) + ".get")]
150+
[ExpectedWarning ("IL2114", nameof (AnnotatedPublicProperties), nameof (DAMProperty) + ".get")]
137151
get;
138152
}
139153
}
@@ -201,6 +215,7 @@ public void RUCMethod () { }
201215
}
202216

203217
[KeptBaseType (typeof (AnnotatedBase))]
218+
// Warning about base member could go away with https://github.com/mono/linker/issues/2175
204219
[ExpectedWarning ("IL2113", "--RUC on AnnotatedBase--")]
205220
class DerivedFromAnnotatedBase : AnnotatedBase
206221
{
@@ -212,7 +227,6 @@ public void RUCMethod () { }
212227
}
213228

214229
[KeptMember (".ctor()")]
215-
[KeptMember ("get_DAMTVirtualProperty()")]
216230
class Base
217231
{
218232
[Kept]
@@ -228,21 +242,21 @@ public virtual void RUCVirtualMethod () { }
228242
[Kept]
229243
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
230244
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicMethods)]
231-
public string DAMTField1;
245+
public string DAMField1;
232246

233247
[Kept]
234248
[KeptBackingField]
235249
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
236250
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicMethods)]
237-
public virtual string DAMTVirtualProperty { get; }
251+
public virtual string DAMVirtualProperty { [Kept] get; }
238252
}
239253

240254
[KeptBaseType (typeof (Base))]
241255
[KeptMember (".ctor()")]
242-
[KeptMember ("get_DAMTVirtualProperty()")]
256+
[KeptMember ("get_DAMVirtualProperty()")]
243257
[ExpectedWarning ("IL2113", "--RUCBaseMethod--")]
244258
[ExpectedWarning ("IL2113", "--Base.RUCVirtualMethod--")]
245-
[ExpectedWarning ("IL2115", nameof (Base), nameof (Base.DAMTVirtualProperty) + ".get")]
259+
[ExpectedWarning ("IL2115", nameof (Base), nameof (Base.DAMVirtualProperty) + ".get")]
246260
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
247261
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
248262
class AnnotatedDerivedFromBase : Base
@@ -262,28 +276,29 @@ public override void RUCVirtualMethod () { }
262276
[Kept]
263277
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
264278
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicMethods)]
265-
public string DAMTField2;
279+
public string DAMField2;
266280

267281
[Kept]
268282
[KeptBackingField]
269283
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
270284
// shouldn't warn because we warn on the base getter instead
271285
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicMethods)]
272-
public override string DAMTVirtualProperty { get; }
286+
public override string DAMVirtualProperty { get; }
273287

274288
}
275289

276290
[KeptBaseType (typeof (AnnotatedDerivedFromBase))]
277291
[KeptMember (".ctor()")]
278-
[KeptMember ("get_DAMTVirtualProperty()")]
292+
[KeptMember ("get_DAMVirtualProperty()")]
279293
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
280294
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)]
281-
[ExpectedWarning ("IL2115", nameof (Base), nameof (DAMTField1))]
282-
[ExpectedWarning ("IL2115", nameof (AnnotatedDerivedFromBase), nameof (DAMTField2))]
295+
// Warnings about base members could go away with https://github.com/mono/linker/issues/2175
296+
[ExpectedWarning ("IL2115", nameof (Base), nameof (DAMField1))]
297+
[ExpectedWarning ("IL2115", nameof (AnnotatedDerivedFromBase), nameof (DAMField2))]
283298
[ExpectedWarning ("IL2113", "--RUCBaseMethod--")]
284299
[ExpectedWarning ("IL2113", "--Base.RUCVirtualMethod--")]
285300
[ExpectedWarning ("IL2113", "--RUC on AnnotatedDerivedFromBase--")]
286-
[ExpectedWarning ("IL2115", nameof (Base), nameof (Base.DAMTVirtualProperty) + ".get")]
301+
[ExpectedWarning ("IL2115", nameof (Base), nameof (Base.DAMVirtualProperty) + ".get")]
287302
class DerivedFromAnnotatedDerivedFromBase : AnnotatedDerivedFromBase
288303
{
289304
[Kept]
@@ -299,17 +314,17 @@ public void RUCMethod () { }
299314
public override void RUCVirtualMethod () { }
300315

301316
[Kept]
302-
[ExpectedWarning ("IL2114", nameof (DerivedFromAnnotatedDerivedFromBase), nameof (DAMTField3))]
317+
[ExpectedWarning ("IL2114", nameof (DerivedFromAnnotatedDerivedFromBase), nameof (DAMField3))]
303318
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
304319
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicMethods)]
305-
public string DAMTField3;
320+
public string DAMField3;
306321

307322
[Kept]
308323
[KeptBackingField]
309324
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
310325
// shouldn't warn because we warn on the base getter instead
311326
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicMethods)]
312-
public override string DAMTVirtualProperty { get; }
327+
public override string DAMVirtualProperty { get; }
313328
}
314329

315330
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]

0 commit comments

Comments
 (0)