dotnet/roslyn

Unclear error message for pointer types in pattern matching

Open

#43,339 opened on Apr 14, 2020

View on GitHub
 (0 comments) (0 reactions) (0 assignees)C# (4,257 forks)batch import
Area-CompilersConcept-Diagnostic ClarityFeature - Pattern Matchinghelp wanted

Repository metrics

Stars
 (20,414 stars)
PR merge metrics
 (Avg merge 6d 17h) (256 merged PRs in 30d)

Description

unsafe class C
{
    static void Main()
    {
        int* ptr = null;
        _ = ptr is var (x); // error CS8521: Pattern-matching is not permitted for pointer types.
        _ = ptr is var y; // valid code
    }
}

The error message shown above doesn't mention anything about parenthesized patterns, despite the fact that that's the only difference between those two lines. We can make this clearer.

Contributor guide