Repository: dotnet/roslyn
File: src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs (C#)

Code before:
                );
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/45616")]
        public void ForeachOnDefaultArray()
        {
            var source = """
                class C
                {
                    static void Main()
                    {
                        try
                        {
                            foreach (int x in default(int[]))
                            {
                            }
                        }
                        catch (System.NullReferenceException)
                        {
                            System.Console.Write("NullReferenceException");
                        }
                    }
                }
                """;

            CompileAndVerify(source, expectedOutput: "NullReferenceException");
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/45616")]
        public void ForeachOnDefaultString()
        {
            var source = """
                class C
                {
                    static void Main()
                    {
                        try
                        {
                            foreach (char c in default(string))
                            {
                            }
                        }
                        catch (System.NullReferenceException)
                        {
                            System.Console.Write("NullReferenceException");
                        }
                    }
                }
                """;

            CompileAndVerify(source, expectedOutput: "NullReferenceException");

Review comment (suggestion):
@copilot Add `.VerifyDiagnostics()` to all the `CompileAndVerify` calls you added. For example: `CompileAndVerify(source, expectedOutput: "NullReferenceException").VerifyDiagnostics();`

Code after:
                );
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/45616")]
        public void ForeachOnDefaultArray()
        {
            var source = """
                class C
                {
                    static void Main()
                    {
                        try
                        {
                            foreach (int x in default(int[]))
                            {
                            }
                        }
                        catch (System.NullReferenceException)
                        {
                            System.Console.Write("NullReferenceException");
                        }
                    }
                }
                """;

            CompileAndVerify(source, expectedOutput: "NullReferenceException").VerifyDiagnostics();
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/45616")]
        public void ForeachOnDefaultString()
        {
            var source = """
                class C
                {
                    static void Main()
                    {
                        try
                        {
                            foreach (char c in default(string))
                            {
                            }
                        }
                        catch (System.NullReferenceException)
                        {
                            System.Console.Write("NullReferenceException");
                        }
                    }
                }
                """;

            CompileAndVerify(source, expectedOutput: "NullReferenceException").VerifyDiagnostics();