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

Code before:
{
    static async Task Main()
    {
        await new Task();
    }
}";

            var corlibRef = CreateEmptyCompilation(corlib, 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
}
");
        }

        [Fact]
        public void AsyncMainWithHandleAsyncEntryPoint_TaskOfInt()
        {
            var corlib = @"
namespace System
{
    public class Object { }
    public class Void { }
    public abstract class ValueType { }
    public struct Int32 { }
    public struct Boolean { }
    public class String { }
    public class Exception { }
    public class Attribute { }
    public abstract class Enum : ValueType { }
    public abstract class Delegate { }
    public abstract class MulticastDelegate : Delegate { }
    public delegate void Action();
    public class Type { }
    public struct IntPtr { }
    public struct RuntimeTypeHandle { }
    public struct RuntimeFieldHandle { }
    
    namespace Threading.Tasks
    {
        public class Task<T>
        {
            public TaskAwaiter<T> GetAwaiter() => default;
        }

Review comment (refactor):
@copilot extract this string and the ones used in the other tests to a single string shared by all of them, and have it include both `AsyncHelpers` methods. The fallback test should use `compilation.MakeMemberMissing` to test the lack of the API. Also, we should have fallback tests for both `void` and `int` mains. #Resolved

Code after:
                        {
                            return task.GetAwaiter().GetResult();
                        }
                    }

                    public struct TaskAwaiter<TResult> : ICriticalNotifyCompletion
                    {
                        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);