Skip to content

False positive in IDE0078 (use of pattern matching) #57199

@kindermannhubert

Description

@kindermannhubert

Version Used: 17.0.0 RC

Steps to Reproduce:

static class C
{
    public struct S1 : I { }
    public struct S2 : I { }
    public interface I { }
}

class Test<T>
{
    public readonly T C;
    bool P => C is C.S1 || C is C.S2; // IDE0078 false positive
}

IDE0078 suggests use of pattern matching. But code with pattern matching:

bool P => C is C.S1 or C.S2;

does not build with following error:
CS1061: 'T' does not contain a definition for 'S1' and no accessible extension method 'S1' accepting a first argument of type 'T' could be found (are you missing a using directive or an assembly reference?)
because C in pattern matching refers to instance field.

Metadata

Metadata

Assignees

Labels

Area-IDEBugIDE-CodeStyleBuilt-in analyzers, fixes, and refactoringshelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions