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

Code before:
                    {
                        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: verify);
            verifier.VerifyDiagnostics();

            void verify(ModuleSymbol module)
            {
                var type = module.GlobalNamespace.GetMember<NamedTypeSymbol>("Test");
                var asyncMethod = type.GetMember<MethodSymbol>("F");

                var attributes = asyncMethod.GetAttributes();

                // When runtime async is enabled, no state machine is generated,
                // so there should be no AsyncStateMachineAttribute and no DebuggerStepThroughAttribute
                Assert.Empty(attributes);

                // Verify no state machine type was generated
                Assert.Empty(type.GetTypeMembers("<F>d__0"));
            }
        }
        #endregion

        #region IteratorStateMachineAttribute
        [Theory]
        [MemberData(nameof(OptimizationLevelTheoryData))]
        public void IteratorStateMachineAttribute_Method(OptimizationLevel optimizationLevel)
        {
            string source = @"
using System.Collections.Generic;

class Test
{
    public static IEnumerable<int> F()
    {
        yield return 1;
    }
}";

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

            CompileAndVerify(CreateCompilationWithMscorlib461(source, options: options), symbolValidator: module =>
            {

Review comment (suggestion):
>"<F>d__0" [](http://example.com/codeflow?start=49&length=9)

I have no idea whether this name is the right name to use. I assume we don't expect to have any nested types. Let's assert that instead. #Closed

Code after:
                    {
                        await Task.Delay(0);
                    }
                }
                """;

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

            var compilation = CreateRuntimeAsyncCompilation(source, options);
            var verifier = CompileAndVerify(compilation, verify: Verification.Skipped, symbolValidator: static module =>
            {
                var type = module.GlobalNamespace.GetMember<NamedTypeSymbol>("Test");
                var asyncMethod = type.GetMember<MethodSymbol>("F");

                // When runtime async is enabled, no state machine is generated,
                // so there should be no AsyncStateMachineAttribute and no DebuggerStepThroughAttribute
                Assert.Empty(asyncMethod.GetAttributes());

                // Verify no state machine types were generated
                Assert.Empty(type.GetTypeMembers());
            });
            verifier.VerifyDiagnostics();
        }

        [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");