break;
case ILOpcode.stsfld:
+ case ILOpcode.ldsfld:
{
// Same as above, but stsfld instead of a call to the constructor
+ // Ldsfld may also trigger a cctor that creates a closure environment
FieldDesc? field = methodBody.GetObject(reader.ReadILToken()) as FieldDesc;
if (field == null)
continue;
break;
case ILOpcode.stsfld:
+ case ILOpcode.ldsfld:
{
if (body.GetObject(reader.ReadILToken()) is FieldDesc { OwningType: MetadataType owningType }
&& compilerGeneratedType == owningType.GetTypeDefinition())
case OperandType.InlineField: {
// Same as above, but stsfld instead of a call to the constructor
- if (instruction.OpCode.Code is not Code.Stsfld)
+ // Ldsfld may also trigger a cctor that creates a closure environment
+ if (instruction.OpCode.Code is not (Code.Stsfld or Code.Ldsfld))
continue;
FieldDefinition? field = _context.TryResolve ((FieldReference) instruction.Operand);
handled = true;
}
break;
- case Code.Stsfld: {
+ case Code.Stsfld:
+ case Code.Ldsfld: {
if (instr.Operand is FieldReference { DeclaringType: GenericInstanceType typeRef }
&& compilerGeneratedType == context.TryResolve (typeRef)) {
return typeRef;
CapturingLocalFunctionInsideIterator<int> ();
LambdaInsideAsync<int> ();
LocalFunctionInsideAsync<int> ();
+ NestedStaticLambda.Test<int> ();
}
private static void UseIterator ()
await Task.Delay (0);
LocalFunction ();
}
+
+ class NestedStaticLambda
+ {
+ public static class Container<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] T> {
+ public static Func<Func<T, T>, Func<T, T>> NestedLambda =
+ (Func<T, T> x) => v => x(v);
+ }
+
+ [ExpectedWarning ("IL2091", "T", nameof (Container<T>), nameof (DynamicallyAccessedMemberTypes.PublicMethods),
+ // https://github.com/dotnet/runtime/issues/84918
+ ProducedBy = Tool.Trimmer | Tool.NativeAot)]
+ public static void Test<T> ()
+ {
+ Container<T>.NestedLambda ((T t) => t) (default (T));
+ }
+ }
}
}