@@ -97,7 +97,6 @@ public static void Test ()
97
97
class EnumTypeSatisfiesPublicFields
98
98
{
99
99
[ Kept ]
100
- [ ExpectedWarning ( "IL2072" ) ]
101
100
static void ParameterType ( Enum instance )
102
101
{
103
102
instance . GetType ( ) . RequiresPublicFields ( ) ;
@@ -113,7 +112,6 @@ class FieldType
113
112
public FieldType ( Enum instance ) => field = instance ;
114
113
115
114
[ Kept ]
116
- [ ExpectedWarning ( "IL2072" ) ]
117
115
public void Test ( )
118
116
{
119
117
field . GetType ( ) . RequiresPublicFields ( ) ;
@@ -134,18 +132,36 @@ static Enum ReturnType ()
134
132
}
135
133
136
134
[ Kept ]
137
- [ ExpectedWarning ( "IL2072" ) ]
138
135
static void TestReturnType ( )
139
136
{
140
137
ReturnType ( ) . GetType ( ) . RequiresPublicFields ( ) ;
141
138
}
142
139
140
+ [ Kept ]
141
+ static void OutParameter ( out Enum value )
142
+ {
143
+ value = EnumType . Value ;
144
+ }
145
+
146
+ [ Kept ]
147
+ // Analyzer doesn't assign a value to the out parameter after calling the OutParameter method,
148
+ // so when it looks up the value of the local 'value', it returns an empty value, and the
149
+ // GetType intrinsic handling can't see that the out param satisfies the public fields requirement.
150
+ // Similar for the other cases below.
151
+ [ ExpectedWarning ( "IL2072" , Tool . Analyzer , "https://github.com/dotnet/runtime/issues/101734" ) ]
152
+ static void TestOutParameter ( )
153
+ {
154
+ OutParameter ( out var value ) ;
155
+ value . GetType ( ) . RequiresPublicFields ( ) ;
156
+ }
157
+
143
158
[ Kept ]
144
159
public static void Test ( )
145
160
{
146
161
ParameterType ( EnumType . Value ) ;
147
162
new FieldType ( EnumType . Value ) . Test ( ) ;
148
163
TestReturnType ( ) ;
164
+ TestOutParameter ( ) ;
149
165
}
150
166
}
151
167
@@ -173,10 +189,10 @@ public static void TestAccessFromType ()
173
189
174
190
// Note: this doesn't warn for ILLink as a consequence of https://github.com/dotnet/runtime/issues/105345.
175
191
// ILLink sees the field type as a generic parameter, whereas the other tools see it as System.Enum.
176
- // The special handling that treats Enum as satisfying PublicFields only applies to generic parameter constraints ,
177
- // so ILLink doesn't warn here. Once this 105345 is fixed, ILLink should match the warning behavior of ILC
178
- // here and in the similar cases below.
179
- [ ExpectedWarning ( "IL2072" , Tool . NativeAot | Tool . Analyzer , "https://github.com/dotnet/runtime/issues/105345" ) ]
192
+ // The other tools don't warn because of the built-in handling for variables of type System.Enum ,
193
+ // and ILLink doesn't warn because this goes through the case that handles generic parameters constrained to be Enum.
194
+ // When https://github.com/dotnet/runtime/issues/105345 is fixed this should go through the built-in handling for
195
+ // System.Enum, like it does for ILC and the analyzer.
180
196
static void TestAccessTypeGenericParameterAsField ( )
181
197
{
182
198
TypeGenericParameterAsField < Enum > . field . GetType ( ) . RequiresPublicFields ( ) ;
@@ -214,7 +230,7 @@ public static void TestAccessFromType ()
214
230
}
215
231
}
216
232
217
- [ ExpectedWarning ( "IL2072" , Tool . NativeAot | Tool . Analyzer , " https://github.com/dotnet/runtime/issues/105345" ) ]
233
+ // Note: this happens to work for ILLink due to https://github.com/dotnet/runtime/issues/105345.
218
234
static void TestAccessTypeGenericParameterAsReturnType ( )
219
235
{
220
236
TypeGenericParameterAsReturnType < Enum > . Method ( ) . GetType ( ) . RequiresPublicFields ( ) ;
@@ -230,15 +246,15 @@ public static void Method (out T instance)
230
246
}
231
247
232
248
[ Kept ]
233
- [ ExpectedWarning ( "IL2072" ) ]
249
+ [ ExpectedWarning ( "IL2072" , Tool . Analyzer , "https://github.com/dotnet/runtime/issues/101734" ) ]
234
250
public static void TestAccessFromType ( )
235
251
{
236
252
Method ( out var instance ) ;
237
253
instance . GetType ( ) . RequiresPublicFields ( ) ;
238
254
}
239
255
}
240
256
241
- [ ExpectedWarning ( "IL2072" ) ]
257
+ [ ExpectedWarning ( "IL2072" , Tool . Analyzer , "https://github.com/dotnet/runtime/issues/101734" ) ]
242
258
static void TestAccessTypeGenericParameterAsOutParam ( )
243
259
{
244
260
TypeGenericParameterAsOutParam < Enum > . Method ( out var instance ) ;
@@ -259,7 +275,7 @@ static T MethodGenericParameterAsReturnType<T> () where T : Enum
259
275
}
260
276
261
277
[ Kept ]
262
- [ ExpectedWarning ( "IL2072" , Tool . NativeAot | Tool . Analyzer , " https://github.com/dotnet/runtime/issues/105345" ) ]
278
+ // Note: this happens to work for ILLink due to https://github.com/dotnet/runtime/issues/105345.
263
279
static void TestMethodGenericParameterAsReturnType ( )
264
280
{
265
281
MethodGenericParameterAsReturnType < Enum > ( ) . GetType ( ) . RequiresPublicFields ( ) ;
0 commit comments