@@ -39,6 +39,7 @@ public static void Main ()
39
39
KeepFieldOnAttribute ( ) ;
40
40
AttributeParametersAndProperties . Test ( ) ;
41
41
MembersOnClassWithRequires < int > . Test ( ) ;
42
+ ConstFieldsOnClassWithRequires . Test ( ) ;
42
43
}
43
44
44
45
[ RequiresUnreferencedCode ( "Message for --ClassWithRequires--" ) ]
@@ -1229,5 +1230,60 @@ public static void Test (ClassWithRequires inst = null)
1229
1230
var j = new GenericAnnotatedWithWarningWithRequires < int > ( ) ;
1230
1231
}
1231
1232
}
1233
+
1234
+ class ConstFieldsOnClassWithRequires
1235
+ {
1236
+ [ RequiresUnreferencedCode ( "--ConstClassWithRequires--" ) ]
1237
+ [ RequiresDynamicCode ( "--ConstClassWithRequires--" ) ]
1238
+ class ConstClassWithRequires
1239
+ {
1240
+ public const string Message = "Message" ;
1241
+ public const int Number = 42 ;
1242
+
1243
+ public static void Method ( ) { }
1244
+ }
1245
+
1246
+ // https://github.com/dotnet/runtime/issues/84433
1247
+ [ ExpectedWarning ( "IL2026" , "--ConstClassWithRequires--" , nameof ( ConstClassWithRequires . Message ) , ProducedBy = Tool . Analyzer ) ]
1248
+ [ ExpectedWarning ( "IL3050" , "--ConstClassWithRequires--" , nameof ( ConstClassWithRequires . Message ) , ProducedBy = Tool . Analyzer ) ]
1249
+ [ ExpectedWarning ( "IL2026" , "--ConstClassWithRequires--" , nameof ( ConstClassWithRequires . Number ) , ProducedBy = Tool . Analyzer ) ]
1250
+ [ ExpectedWarning ( "IL3050" , "--ConstClassWithRequires--" , nameof ( ConstClassWithRequires . Number ) , ProducedBy = Tool . Analyzer ) ]
1251
+ [ ExpectedWarning ( "IL2026" , "--ConstClassWithRequires--" , nameof ( ConstClassWithRequires . Method ) ) ]
1252
+ [ ExpectedWarning ( "IL3050" , "--ConstClassWithRequires--" , nameof ( ConstClassWithRequires . Method ) , ProducedBy = Tool . Analyzer | Tool . NativeAot ) ]
1253
+ static void TestClassWithRequires ( )
1254
+ {
1255
+ var a = ConstClassWithRequires . Message ;
1256
+ var b = ConstClassWithRequires . Number ;
1257
+
1258
+ ConstClassWithRequires . Method ( ) ;
1259
+ }
1260
+
1261
+ // https://github.com/dotnet/runtime/issues/84433
1262
+ [ ExpectedWarning ( "IL2026" , "--ConstClassWithRequiresUsingField--" , nameof ( ConstClassWithRequiresUsingField . Message ) , ProducedBy = Tool . Analyzer ) ]
1263
+ [ ExpectedWarning ( "IL3050" , "--ConstClassWithRequiresUsingField--" , nameof ( ConstClassWithRequiresUsingField . Message ) , ProducedBy = Tool . Analyzer ) ]
1264
+ [ RequiresUnreferencedCode ( ConstClassWithRequiresUsingField . Message ) ]
1265
+ [ ExpectedWarning ( "IL2026" , "--ConstClassWithRequiresUsingField--" , nameof ( ConstClassWithRequiresUsingField . Message ) , ProducedBy = Tool . Analyzer ) ]
1266
+ [ ExpectedWarning ( "IL3050" , "--ConstClassWithRequiresUsingField--" , nameof ( ConstClassWithRequiresUsingField . Message ) , ProducedBy = Tool . Analyzer ) ]
1267
+ [ RequiresDynamicCode ( ConstClassWithRequiresUsingField . Message ) ]
1268
+ class ConstClassWithRequiresUsingField
1269
+ {
1270
+ public const string Message = "--ConstClassWithRequiresUsingField--" ;
1271
+
1272
+ public static void Method ( ) { }
1273
+ }
1274
+
1275
+ [ ExpectedWarning ( "IL2026" , "--ConstClassWithRequiresUsingField--" , nameof ( ConstClassWithRequiresUsingField . Method ) ) ]
1276
+ [ ExpectedWarning ( "IL3050" , "--ConstClassWithRequiresUsingField--" , nameof ( ConstClassWithRequiresUsingField . Method ) , ProducedBy = Tool . Analyzer | Tool . NativeAot ) ]
1277
+ static void TestClassUsingFieldInAttribute ( )
1278
+ {
1279
+ ConstClassWithRequiresUsingField . Method ( ) ;
1280
+ }
1281
+
1282
+ public static void Test ( )
1283
+ {
1284
+ TestClassWithRequires ( ) ;
1285
+ TestClassUsingFieldInAttribute ( ) ;
1286
+ }
1287
+ }
1232
1288
}
1233
1289
}
0 commit comments