Repository: dotnet/roslyn
File: src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncTests.cs (C#)

Code before:
            var comp = CreateRuntimeAsyncCompilation(source, options: TestOptions.DebugDll);
            var verifier = CompileAndVerify(comp, verify: Verification.Fails with { ILVerifyMessage = ReturnValueMissing("Main", "0x13") });

            verifier.VerifyIL("Program.Main()", """
                {
                  // Code size       20 (0x14)
                  .maxstack  1
                  // sequence point: {
                  IL_0000:  nop
                  // sequence point: await Task.CompletedTask;
                  IL_0001:  call       "System.Threading.Tasks.Task System.Threading.Tasks.Task.CompletedTask.get"
                  IL_0006:  call       "void System.Runtime.CompilerServices.AsyncHelpers.Await(System.Threading.Tasks.Task)"
                  IL_000b:  nop
                  // sequence point: System.Console.WriteLine(1);
                  IL_000c:  ldc.i4.1
                  IL_000d:  call       "void System.Console.WriteLine(int)"
                  IL_0012:  nop
                  // sequence point: }
                  IL_0013:  ret
                }
                """, sequencePointDisplay: SequencePointDisplayMode.Enhanced);
        }

        [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/82551")]
        [CombinatorialData]
        public void RuntimeAsync_AwaitTaskWhenAll_AsyncLambdaInSelect_InferenceScenarios(bool explicitReturnType, bool statementBody)
        {
            var lambda = (explicitReturnType, statementBody) switch
            {
                (true, true) => "async Task<int> (int x) => { return await Task.FromResult(x); }",
                (true, false) => "async Task<int> (int x) => await Task.FromResult(x)",
                (false, true) => "async x => { return await Task.FromResult(x); }",
                (false, false) => "async x => await Task.FromResult(x)",
            };

            var source = $$"""
                using System.Linq;
                using System.Threading.Tasks;

                class Program
                {
                    static async Task Main()
                    {
                        await Task.WhenAll(new[] { 1, 2, 3 }.Select({{lambda}}));
                    }
                }
                """;

            var comp = CreateRuntimeAsyncCompilation(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.RegularPreview);
            comp.VerifyEmitDiagnostics();
        }

Review comment (suggestion):
>RuntimeAsync_AwaitTaskWhenAll_AsyncLambdaInSelect_InferenceScenarios [](http://example.com/codeflow?start=20&length=68)

It looks like result of ```IsRuntimeAsyncEnabledIn``` can be affected by attributes on the lambda. It doesn't look like the attributes are used in the added tests. #Closed

Code after:
            var comp = CreateRuntimeAsyncCompilation(source, options: TestOptions.DebugDll);
            var verifier = CompileAndVerify(comp, verify: Verification.Fails with { ILVerifyMessage = ReturnValueMissing("Main", "0x13") });

            verifier.VerifyIL("Program.Main()", """
                {
                  // Code size       20 (0x14)
                  .maxstack  1
                  // sequence point: {
                  IL_0000:  nop
                  // sequence point: await Task.CompletedTask;
                  IL_0001:  call       "System.Threading.Tasks.Task System.Threading.Tasks.Task.CompletedTask.get"
                  IL_0006:  call       "void System.Runtime.CompilerServices.AsyncHelpers.Await(System.Threading.Tasks.Task)"
                  IL_000b:  nop
                  // sequence point: System.Console.WriteLine(1);
                  IL_000c:  ldc.i4.1
                  IL_000d:  call       "void System.Console.WriteLine(int)"
                  IL_0012:  nop
                  // sequence point: }
                  IL_0013:  ret
                }
                """, sequencePointDisplay: SequencePointDisplayMode.Enhanced);
        }

        [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/82551")]
        [CombinatorialData]
        public void RuntimeAsync_AwaitTaskWhenAll_AsyncLambdaInSelect_InferenceScenarios(bool explicitReturnType, bool statementBody, bool runtimeAsyncEnabledOnLambda)
        {
            var lambda = (explicitReturnType, statementBody) switch
            {
                (true, true) => "async Task<int> (int x) => { return await Task.FromResult(x); }",
                (true, false) => "async Task<int> (int x) => await Task.FromResult(x)",
                (false, true) => "async (x) => { return await Task.FromResult(x); }",
                (false, false) => "async (x) => await Task.FromResult(x)",
            };
            var lambdaRuntimeAsyncAttribute = $"[System.Runtime.CompilerServices.RuntimeAsyncMethodGenerationAttribute({(runtimeAsyncEnabledOnLambda ? "true" : "false")})] ";

            var source = $$"""
                using System.Linq;
                using System.Threading.Tasks;

                class Program
                {
                    static async Task Main()
                    {
                        await Task.WhenAll(new[] { 1, 2, 3 }.Select({{lambdaRuntimeAsyncAttribute}}{{lambda}}));
                    }
                }
                """;

            var comp = CreateRuntimeAsyncCompilation([source, RuntimeAsyncMethodGenerationAttributeDefinition], options: TestOptions.ReleaseExe, parseOptions: TestOptions.RegularPreview);
            comp.VerifyEmitDiagnostics();