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

Code before:
        {
            var source = @"
using System;
using System.Threading.Tasks;

class Program {
    static async Task Main() {
        Console.Write(""hello "");
        await Task.Factory.StartNew(() => 5);
        Console.Write(""async main"");
    }
}";

            var asyncHelpersSource = @"
namespace System.Runtime.CompilerServices
{
    public static class AsyncHelpers
    {
        public static void HandleAsyncEntryPoint(System.Threading.Tasks.Task task)
        {
            task.GetAwaiter().GetResult();
        }
    }
}";

            var c = CreateCompilationWithMscorlib461(new[] { source, asyncHelpersSource }, options: TestOptions.DebugExe, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp7_1));
            
            CompileAndVerify(c, expectedOutput: "hello async main", expectedReturnCode: 0);
        }

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

class Program {
    static async Task<int> Main() {
        Console.Write(""hello "");
        await Task.Factory.StartNew(() => 5);
        Console.Write(""async main"");
        return 42;
    }
}";

            var asyncHelpersSource = @"
namespace System.Runtime.CompilerServices
{
    public static class AsyncHelpers
    {

Review comment (suggestion):
@Copilot this does not test the scenario. You will need to create a minimal corelib stub that includes the new methods, and reference that from an empty compilation. Do not attempt to verify the expected output of the test, instead use the verifier to verify the IL generated for the compiler-generated `Main` method. #Resolved

Code after:
            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 { }

                public static class Console
                {
                    public static void Write(int value) { }
                }

                namespace Threading.Tasks
                {
                    public class Task
                    {
                        public System.Runtime.CompilerServices.TaskAwaiter GetAwaiter() => default;
                        public static Task Delay(int millisecondsDelay) => default;
                    }

                    public class Task<TResult>
                    {
                        public System.Runtime.CompilerServices.TaskAwaiter<TResult> GetAwaiter() => default;
                    }
                }

                namespace Runtime.CompilerServices
                {
                    public interface INotifyCompletion
                    {
                        void OnCompleted(Action continuation);
                    }

                    public interface ICriticalNotifyCompletion : INotifyCompletion
                    {
                        void UnsafeOnCompleted(Action continuation);
                    }

                    public interface IAsyncStateMachine