diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/CompilerGeneratedState.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/CompilerGeneratedState.cs index 84325bd9058439..400b643abf53cc 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/CompilerGeneratedState.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/CompilerGeneratedState.cs @@ -737,6 +737,10 @@ public bool TryGetUserMethodForCompilerGeneratedMember(TypeSystemEntity sourceMe if (sourceMember == null) return false; + Debug.Assert(sourceMember is not MethodDesc sourceMethod || sourceMethod.IsTypicalMethodDefinition); + if (sourceMember is AsyncMethodVariant asyncVariant) + sourceMember = asyncVariant.Target; + TypeSystemEntity member = sourceMember; MethodDesc? userMethodCandidate; while (TryGetOwningMethodForCompilerGeneratedMember(member, out userMethodCandidate)) diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/RuntimeAsyncMethods.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/RuntimeAsyncMethods.cs index fb594ee52e76cd..a73470c801c178 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/RuntimeAsyncMethods.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/RuntimeAsyncMethods.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.Reflection; using System.Runtime.CompilerServices; using System.Threading.Tasks; using Mono.Linker.Tests.Cases.Expectations.Assertions; @@ -28,6 +29,7 @@ public static async Task Main() await RuntimeAsyncWithCorrectParameter(null); await RuntimeAsyncWithLocalAll(); await RuntimeAsyncWithLambda(); + await RuntimeAsyncWithAwaitedLocalMethod(); } static async Task BasicRuntimeAsyncMethod() @@ -116,5 +118,16 @@ static async Task RuntimeAsyncWithLambda() { await Task.Run([ExpectedWarning("IL2026", nameof(TypeWithRucMethod.RucMethod))] () => typeof(TypeWithRucMethod).GetMethods()); } + + static async Task RuntimeAsyncWithAwaitedLocalMethod() + { + await GetTheMethods(); + + [ExpectedWarning("IL2026", nameof(TypeWithRucMethod.RucMethod))] + static async Task GetTheMethods() + { + return typeof(TypeWithRucMethod).GetMethods(); + } + } } }