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

Code before:
    {
        return 2;
    }
}

class C : System.Collections.ICollection
{
    public int Count => 1;
    public object SyncRoot => throw new NotImplementedException();
    public bool IsSynchronized => throw new NotImplementedException();
    public void CopyTo(Array array, int index) => throw new NotImplementedException();
    public IEnumerator GetEnumerator() => throw new NotImplementedException();
}
""";
        CompileAndVerify(source, expectedOutput: "212").VerifyDiagnostics(
            // (13,18): warning CS8509: The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '_' is not covered.
            //         return c switch
            Diagnostic(ErrorCode.WRN_SwitchExpressionNotExhaustive, "switch").WithArguments("_").WithLocation(13, 18)
            );
    }

    [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/70806")]
    public void PointerType_ListPattern()
    {
        var source = """
unsafe class C
{
    void M()
    {
        void* v = null;
        if (v is [])
        {
        }
    }
}
""";
        var compilation = CreateCompilation(source, options: TestOptions.UnsafeReleaseDll);
        compilation.VerifyDiagnostics(
            // (6,18): error CS8521: Pattern-matching is not permitted for pointer types.
            //         if (v is [])
            Diagnostic(ErrorCode.ERR_PointerTypeInPatternMatching, "[]").WithLocation(6, 18)
            );
    }

    [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/70806")]
    public void FunctionPointerType_ListPattern()
    {
        var source = """
unsafe class C
{
    void M()

Review comment (suggestion):
@copilot  use raw string literals.  Also, fixup all the workitems to point at 70046 instead.  Also place the `);` at the end of the prior line in all teh VerifyDiagnostics calls. 

Code after:
    {
        return 2;
    }
}

class C : System.Collections.ICollection
{
    public int Count => 1;
    public object SyncRoot => throw new NotImplementedException();
    public bool IsSynchronized => throw new NotImplementedException();
    public void CopyTo(Array array, int index) => throw new NotImplementedException();
    public IEnumerator GetEnumerator() => throw new NotImplementedException();
}
""";
        CompileAndVerify(source, expectedOutput: "212").VerifyDiagnostics(
            // (13,18): warning CS8509: The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '_' is not covered.
            //         return c switch
            Diagnostic(ErrorCode.WRN_SwitchExpressionNotExhaustive, "switch").WithArguments("_").WithLocation(13, 18)
            );
    }

    [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/70046")]
    public void PointerType_ListPattern_NoIndex()
    {
        var source = """
            unsafe class C
            {
                void M()
                {
                    void* v = null;
                    if (v is [])
                    {
                    }
                }
            }
            """;
        var compilation = CreateCompilation(source, options: TestOptions.UnsafeReleaseDll);
        compilation.VerifyDiagnostics(
            // (6,18): error CS8985: List patterns may not be used for a value of type 'void*'. No suitable 'Length' or 'Count' property was found.
            //         if (v is [])
            Diagnostic(ErrorCode.ERR_ListPatternRequiresLength, "[]").WithArguments("void*").WithLocation(6, 18),
            // (6,18): error CS0518: Predefined type 'System.Index' is not defined or imported
            //         if (v is [])
            Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, "[]").WithArguments("System.Index").WithLocation(6, 18),
            // (6,18): error CS0242: The operation in question is undefined on void pointers
            //         if (v is [])
            Diagnostic(ErrorCode.ERR_VoidError, "[]").WithLocation(6, 18));

        var semanticModel = compilation.GetSemanticModel(compilation.SyntaxTrees.Single());
        var pattern = compilation.SyntaxTrees.Single().GetRoot().DescendantNodes().OfType<IsPatternExpressionSyntax>().Single();
        compilation.VerifyOperationTree(pattern, """