diff --git a/src/tests/async/awaitingnoasyncgeneric/awaitingnoasyncgeneric.cs b/src/tests/async/awaitingnoasyncgeneric/awaitingnoasyncgeneric.cs new file mode 100644 index 00000000000000..d0bc7e99b31f5d --- /dev/null +++ b/src/tests/async/awaitingnoasyncgeneric/awaitingnoasyncgeneric.cs @@ -0,0 +1,37 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.CompilerServices; +using System.Threading.Tasks; +using Xunit; + +public class AwaitingNoAsyncGeneric +{ + [Fact] + public static void TestEntryPoint() + { + Assert.Equal("hello", new Caller().RunAsync("hello").GetAwaiter().GetResult()); + Assert.Equal(42, new Caller().RunAsync(42).GetAwaiter().GetResult()); + } +} + +public class Caller +{ + [MethodImpl(MethodImplOptions.NoInlining)] + public async ValueTask RunAsync(T value) + { + return await Helper.GetValueAsync(value).ConfigureAwait(false); + } +} + +public static class Helper +{ + // Non-async method returning ValueTask, so the compiler does not emit + // MethodImplAttributes.Async. This is the condition that can trigger a + // scanner/JIT mismatch. + [MethodImpl(MethodImplOptions.NoInlining)] + public static ValueTask GetValueAsync(T value) + { + return new ValueTask(value); + } +} diff --git a/src/tests/async/awaitingnoasyncgeneric/awaitingnoasyncgeneric.csproj b/src/tests/async/awaitingnoasyncgeneric/awaitingnoasyncgeneric.csproj new file mode 100644 index 00000000000000..e72445fd68b707 --- /dev/null +++ b/src/tests/async/awaitingnoasyncgeneric/awaitingnoasyncgeneric.csproj @@ -0,0 +1,11 @@ + + + + true + + true + + + + +