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

Code before:
                    {
                        public bool IsCompleted => true;
                        public void GetResult() { }
                        public void OnCompleted(Action continuation) { }
                        public void UnsafeOnCompleted(Action continuation) { }
                    }
                }

                public enum AttributeTargets { All = ~0 }

                [AttributeUsage(AttributeTargets.All)]
                public sealed class AttributeUsageAttribute : Attribute
                {
                    public AttributeUsageAttribute(AttributeTargets validOn) { }
                    public bool AllowMultiple { get; set; }
                    public bool Inherited { get; set; }
                }
            }

            namespace System.Diagnostics
            {
                public class DebuggerStepThroughAttribute : Attribute { }
            }
            """;

        [Fact]
        public void AsyncMainWithHandleAsyncEntryPoint_Task()
        {
            var source = """
                using System.Threading.Tasks;

                class Program
                {
                    static async Task Main()
                    {
                        await new Task();
                    }
                }
                """;

            var corlibRef = CreateEmptyCompilation(MinimalAsyncCorelibWithAsyncHelpers, assemblyName: "mincorlib").EmitToImageReference();
            var comp = CreateEmptyCompilation(source, references: new[] { corlibRef }, options: TestOptions.DebugExe);

            var verifier = CompileAndVerify(comp, verify: Verification.Skipped);
            verifier.VerifyIL("Program.<Main>()", """
                {
                  // Code size       11 (0xb)
                  .maxstack  1
                  IL_0000:  call       "System.Threading.Tasks.Task Program.Main()"
                  IL_0005:  call       "void System.Runtime.CompilerServices.AsyncHelpers.HandleAsyncEntryPoint(System.Threading.Tasks.Task)"
                  IL_000a:  ret

Review comment (bug):
Consider adding WorkItem attributes (unless we only add those for bugs, not features?) #Resolved

Code after:
                        public bool IsCompleted => true;
                        public TResult GetResult() => default;
                        public void OnCompleted(Action continuation) { }
                        public void UnsafeOnCompleted(Action continuation) { }
                    }

                    public struct TaskAwaiter : ICriticalNotifyCompletion
                    {
                        public bool IsCompleted => true;
                        public void GetResult() { }
                        public void OnCompleted(Action continuation) { }
                        public void UnsafeOnCompleted(Action continuation) { }
                    }
                }

                public enum AttributeTargets { All = ~0 }

                [AttributeUsage(AttributeTargets.All)]
                public sealed class AttributeUsageAttribute : Attribute
                {
                    public AttributeUsageAttribute(AttributeTargets validOn) { }
                    public bool AllowMultiple { get; set; }
                    public bool Inherited { get; set; }
                }
            }

            namespace System.Diagnostics
            {
                public class DebuggerStepThroughAttribute : Attribute { }
            }
            """;

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/80873")]
        public void AsyncMainWithHandleAsyncEntryPoint_Task()
        {
            var source = """
                using System;
                using System.Threading.Tasks;

                class Program
                {
                    static async Task Main()
                    {
                        await Task.Delay(1);
                        Console.Write(1);
                    }
                }
                """;

            var corlibRef = CreateEmptyCompilation(MinimalAsyncCorelibWithAsyncHelpers, assemblyName: "mincorlib").VerifyDiagnostics().EmitToImageReference();
            var comp = CreateEmptyCompilation(source, references: [corlibRef], options: TestOptions.DebugExe);