diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/CompilerGeneratedTypes.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/CompilerGeneratedTypes.cs index c051625d3f767f..719c95bc2d2a53 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/CompilerGeneratedTypes.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/CompilerGeneratedTypes.cs @@ -50,6 +50,9 @@ public static void Main() NestedAsyncLambda.Test(); NestedAsyncLocalFunction.Test(); NestedStaticLambda.Test(); + + // Partial methods + PartialAsyncMethodWithLambda.Test(); } private static void UseIterator() @@ -433,5 +436,32 @@ public static void Test() Container.NestedLambda((T t) => t)(default(T)); } } + + // Regression test for https://github.com/dotnet/runtime/issues/122800 + // Roslyn does not emit [AsyncStateMachineAttribute] on async partial methods. + partial class PartialAsyncMethodWithLambda + { + public static void Test() + { + new PartialAsyncMethodWithLambda().GetData(); + } + + public partial Task GetData() where T : new(); + } + + partial class PartialAsyncMethodWithLambda + { + public async partial Task GetData<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] T>() where T : new() + { + var tcs = new TaskCompletionSource(); + Action callback = (result) => + { + _ = typeof(T).GetMethods(); + tcs.TrySetResult(result); + }; + callback(new T()); + return await tcs.Task; + } + } } }