@@ -34,6 +34,10 @@ public static void Main ()
34
34
35
35
// Instantiate this type just so its property getters are considered reachable
36
36
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 ;
37
41
}
38
42
39
43
[ Kept ]
@@ -68,8 +72,8 @@ class AnnotatedAll
68
72
[ Kept ]
69
73
[ KeptAttributeAttribute ( typeof ( DynamicallyAccessedMembersAttribute ) ) ]
70
74
[ 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 ;
73
77
74
78
[ Kept ]
75
79
[ KeptAttributeAttribute ( typeof ( RequiresUnreferencedCodeAttribute ) ) ]
@@ -78,8 +82,8 @@ class AnnotatedAll
78
82
public void RUCMethod ( ) { }
79
83
80
84
[ Kept ]
81
- [ ExpectedWarning ( "IL2114" , nameof ( AnnotatedAll ) , nameof ( DAMTMethod ) ) ]
82
- public void DAMTMethod (
85
+ [ ExpectedWarning ( "IL2114" , nameof ( AnnotatedAll ) , nameof ( DAMMethod ) ) ]
86
+ public void DAMMethod (
83
87
[ KeptAttributeAttribute ( typeof ( DynamicallyAccessedMembersAttribute ) ) ]
84
88
[ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicMethods ) ]
85
89
Type t
@@ -98,9 +102,19 @@ class AnnotatedPublicMethods
98
102
[ RequiresUnreferencedCode ( "--RUC on AnnotatedPublicMethods.RUCMethod--" ) ]
99
103
public void RUCMethod ( ) { }
100
104
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
+
101
115
[ Kept ]
102
- [ ExpectedWarning ( "IL2114" , nameof ( AnnotatedPublicMethods ) , nameof ( DAMTMethod ) ) ]
103
- public void DAMTMethod (
116
+ [ ExpectedWarning ( "IL2114" , nameof ( AnnotatedPublicMethods ) , nameof ( DAMMethod ) ) ]
117
+ public void DAMMethod (
104
118
[ KeptAttributeAttribute ( typeof ( DynamicallyAccessedMembersAttribute ) ) ]
105
119
[ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicMethods ) ]
106
120
Type t
@@ -116,13 +130,13 @@ class AnnotatedPublicFields
116
130
[ Kept ]
117
131
[ KeptAttributeAttribute ( typeof ( DynamicallyAccessedMembersAttribute ) ) ]
118
132
[ 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 ;
121
135
122
136
}
123
137
124
138
[ Kept ]
125
- [ KeptMember ( "get_DAMTProperty ()" ) ]
139
+ [ KeptMember ( "get_DAMProperty ()" ) ]
126
140
[ KeptAttributeAttribute ( typeof ( DynamicallyAccessedMembersAttribute ) ) ]
127
141
[ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicProperties ) ]
128
142
class AnnotatedPublicProperties
@@ -131,9 +145,9 @@ class AnnotatedPublicProperties
131
145
[ KeptBackingField ]
132
146
[ KeptAttributeAttribute ( typeof ( DynamicallyAccessedMembersAttribute ) ) ]
133
147
[ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicMethods ) ]
134
- public static string DAMTProperty {
148
+ public static string DAMProperty {
135
149
// Property access reports warnings on getter/setter
136
- [ ExpectedWarning ( "IL2114" , nameof ( AnnotatedPublicProperties ) , nameof ( DAMTProperty ) + ".get" ) ]
150
+ [ ExpectedWarning ( "IL2114" , nameof ( AnnotatedPublicProperties ) , nameof ( DAMProperty ) + ".get" ) ]
137
151
get ;
138
152
}
139
153
}
@@ -201,6 +215,7 @@ public void RUCMethod () { }
201
215
}
202
216
203
217
[ KeptBaseType ( typeof ( AnnotatedBase ) ) ]
218
+ // Warning about base member could go away with https://github.com/mono/linker/issues/2175
204
219
[ ExpectedWarning ( "IL2113" , "--RUC on AnnotatedBase--" ) ]
205
220
class DerivedFromAnnotatedBase : AnnotatedBase
206
221
{
@@ -212,7 +227,6 @@ public void RUCMethod () { }
212
227
}
213
228
214
229
[ KeptMember ( ".ctor()" ) ]
215
- [ KeptMember ( "get_DAMTVirtualProperty()" ) ]
216
230
class Base
217
231
{
218
232
[ Kept ]
@@ -228,21 +242,21 @@ public virtual void RUCVirtualMethod () { }
228
242
[ Kept ]
229
243
[ KeptAttributeAttribute ( typeof ( DynamicallyAccessedMembersAttribute ) ) ]
230
244
[ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . NonPublicMethods ) ]
231
- public string DAMTField1 ;
245
+ public string DAMField1 ;
232
246
233
247
[ Kept ]
234
248
[ KeptBackingField ]
235
249
[ KeptAttributeAttribute ( typeof ( DynamicallyAccessedMembersAttribute ) ) ]
236
250
[ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . NonPublicMethods ) ]
237
- public virtual string DAMTVirtualProperty { get ; }
251
+ public virtual string DAMVirtualProperty { [ Kept ] get ; }
238
252
}
239
253
240
254
[ KeptBaseType ( typeof ( Base ) ) ]
241
255
[ KeptMember ( ".ctor()" ) ]
242
- [ KeptMember ( "get_DAMTVirtualProperty ()" ) ]
256
+ [ KeptMember ( "get_DAMVirtualProperty ()" ) ]
243
257
[ ExpectedWarning ( "IL2113" , "--RUCBaseMethod--" ) ]
244
258
[ ExpectedWarning ( "IL2113" , "--Base.RUCVirtualMethod--" ) ]
245
- [ ExpectedWarning ( "IL2115" , nameof ( Base ) , nameof ( Base . DAMTVirtualProperty ) + ".get" ) ]
259
+ [ ExpectedWarning ( "IL2115" , nameof ( Base ) , nameof ( Base . DAMVirtualProperty ) + ".get" ) ]
246
260
[ KeptAttributeAttribute ( typeof ( DynamicallyAccessedMembersAttribute ) ) ]
247
261
[ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicMethods ) ]
248
262
class AnnotatedDerivedFromBase : Base
@@ -262,28 +276,29 @@ public override void RUCVirtualMethod () { }
262
276
[ Kept ]
263
277
[ KeptAttributeAttribute ( typeof ( DynamicallyAccessedMembersAttribute ) ) ]
264
278
[ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . NonPublicMethods ) ]
265
- public string DAMTField2 ;
279
+ public string DAMField2 ;
266
280
267
281
[ Kept ]
268
282
[ KeptBackingField ]
269
283
[ KeptAttributeAttribute ( typeof ( DynamicallyAccessedMembersAttribute ) ) ]
270
284
// shouldn't warn because we warn on the base getter instead
271
285
[ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . NonPublicMethods ) ]
272
- public override string DAMTVirtualProperty { get ; }
286
+ public override string DAMVirtualProperty { get ; }
273
287
274
288
}
275
289
276
290
[ KeptBaseType ( typeof ( AnnotatedDerivedFromBase ) ) ]
277
291
[ KeptMember ( ".ctor()" ) ]
278
- [ KeptMember ( "get_DAMTVirtualProperty ()" ) ]
292
+ [ KeptMember ( "get_DAMVirtualProperty ()" ) ]
279
293
[ KeptAttributeAttribute ( typeof ( DynamicallyAccessedMembersAttribute ) ) ]
280
294
[ 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 ) ) ]
283
298
[ ExpectedWarning ( "IL2113" , "--RUCBaseMethod--" ) ]
284
299
[ ExpectedWarning ( "IL2113" , "--Base.RUCVirtualMethod--" ) ]
285
300
[ ExpectedWarning ( "IL2113" , "--RUC on AnnotatedDerivedFromBase--" ) ]
286
- [ ExpectedWarning ( "IL2115" , nameof ( Base ) , nameof ( Base . DAMTVirtualProperty ) + ".get" ) ]
301
+ [ ExpectedWarning ( "IL2115" , nameof ( Base ) , nameof ( Base . DAMVirtualProperty ) + ".get" ) ]
287
302
class DerivedFromAnnotatedDerivedFromBase : AnnotatedDerivedFromBase
288
303
{
289
304
[ Kept ]
@@ -299,17 +314,17 @@ public void RUCMethod () { }
299
314
public override void RUCVirtualMethod ( ) { }
300
315
301
316
[ Kept ]
302
- [ ExpectedWarning ( "IL2114" , nameof ( DerivedFromAnnotatedDerivedFromBase ) , nameof ( DAMTField3 ) ) ]
317
+ [ ExpectedWarning ( "IL2114" , nameof ( DerivedFromAnnotatedDerivedFromBase ) , nameof ( DAMField3 ) ) ]
303
318
[ KeptAttributeAttribute ( typeof ( DynamicallyAccessedMembersAttribute ) ) ]
304
319
[ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . NonPublicMethods ) ]
305
- public string DAMTField3 ;
320
+ public string DAMField3 ;
306
321
307
322
[ Kept ]
308
323
[ KeptBackingField ]
309
324
[ KeptAttributeAttribute ( typeof ( DynamicallyAccessedMembersAttribute ) ) ]
310
325
// shouldn't warn because we warn on the base getter instead
311
326
[ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . NonPublicMethods ) ]
312
- public override string DAMTVirtualProperty { get ; }
327
+ public override string DAMVirtualProperty { get ; }
313
328
}
314
329
315
330
[ KeptAttributeAttribute ( typeof ( DynamicallyAccessedMembersAttribute ) ) ]
0 commit comments