Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ referencedMethod.OwningType is MetadataType generatedType &&
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;
Expand Down Expand Up @@ -417,6 +419,7 @@ void MapGeneratedTypeTypeParameters(
break;

case ILOpcode.stsfld:
case ILOpcode.ldsfld:
{
if (body.GetObject(reader.ReadILToken()) is FieldDesc { OwningType: MetadataType owningType }
&& compilerGeneratedType == owningType.GetTypeDefinition())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ referencedMethod.DeclaringType is var generatedType &&

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);
Expand Down Expand Up @@ -390,7 +391,8 @@ static void MapGeneratedTypeTypeParameters (
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static void Main ()
CapturingLocalFunctionInsideIterator<int> ();
LambdaInsideAsync<int> ();
LocalFunctionInsideAsync<int> ();
NestedStaticLambda.Test<int> ();
}

private static void UseIterator ()
Expand Down Expand Up @@ -352,5 +353,21 @@ void LocalFunction ()
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));
}
}
}
}