Repository: dotnet/roslyn
File: src/Compilers/CSharp/Test/Emit3/Attributes/AttributeTests_Synthesized.cs (C#)

Code before:

        [Theory]
        [MemberData(nameof(OptimizationLevelTheoryData))]
        public void AsyncStateMachineAttribute_RuntimeAsync_Lambda(OptimizationLevel optimizationLevel)
        {
            string source = """
                using System;
                using System.Threading.Tasks;

                class Test
                {
                    public static void F()
                    {
                        Func<Task> f = async () => { await Task.Delay(0); };
                    }
                }
                """;

            var options = TestOptions.CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel)
                .WithMetadataImportOptions(MetadataImportOptions.All);

            var compilation = CreateRuntimeAsyncCompilation(source, options);
            var verifier = CompileAndVerify(compilation, verify: Verification.Skipped, symbolValidator: static module =>
            {
                var type = module.GlobalNamespace.GetMember<NamedTypeSymbol>("Test");
                var closureClass = type.GetTypeMembers().Single(t => t.Name == "<>c");
                var asyncMethod = closureClass.GetMember<MethodSymbol>("<F>b__0_0");
                Assert.Empty(asyncMethod.GetAttributes().SelectAsArray(a => a.AttributeConstructor.ToTestDisplayString()));

                // No state machine types should be generated for the lambda when runtime async is enabled
                Assert.Empty(closureClass.GetTypeMembers());
            });
            verifier.VerifyDiagnostics();
        }

        [Theory]
        [MemberData(nameof(OptimizationLevelTheoryData))]
        public void AsyncStateMachineAttribute_RuntimeAsync_LocalFunction(OptimizationLevel optimizationLevel)
        {
            string source = """
                using System.Threading.Tasks;

                class Test
                {
                    public static async Task F()
                    {
                        async Task LocalAsync() { await Task.Delay(0); }
                        await LocalAsync();
                    }
                }
                """;

Review comment (suggestion):
>type.GetTypeMembers().Single(t => t.Name == "<>c") [](http://example.com/codeflow?start=35&length=50)

Probably can be simpified to `type.GetTypeMember("<>c")`

Code after:

        [Theory]
        [MemberData(nameof(OptimizationLevelTheoryData))]
        public void AsyncStateMachineAttribute_RuntimeAsync_Lambda(OptimizationLevel optimizationLevel)
        {
            string source = """
                using System;
                using System.Threading.Tasks;

                class Test
                {
                    public static void F()
                    {
                        Func<Task> f = async () => { await Task.Delay(0); };
                    }
                }
                """;

            var options = TestOptions.CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel)
                .WithMetadataImportOptions(MetadataImportOptions.All);

            var compilation = CreateRuntimeAsyncCompilation(source, options);
            var verifier = CompileAndVerify(compilation, verify: Verification.Skipped, symbolValidator: static module =>
            {
                var type = module.GlobalNamespace.GetMember<NamedTypeSymbol>("Test");
                var closureClass = type.GetTypeMembers().Single();
                Assert.Equal("<>c", closureClass.Name);
                var asyncMethod = closureClass.GetMember<MethodSymbol>("<F>b__0_0");
                Assert.Empty(asyncMethod.GetAttributes());

                // No state machine types should be generated for the lambda when runtime async is enabled
                Assert.Empty(closureClass.GetTypeMembers());
            });
            verifier.VerifyDiagnostics();
        }

        [Theory]
        [MemberData(nameof(OptimizationLevelTheoryData))]
        public void AsyncStateMachineAttribute_RuntimeAsync_LocalFunction(OptimizationLevel optimizationLevel)
        {
            string source = """
                using System.Threading.Tasks;

                class Test
                {
                    public static async Task F()
                    {
                        async Task LocalAsync() { await Task.Delay(0); }
                        await LocalAsync();
                    }
                }