Skip to content

Discrepancy between IDE0072 and CS8510 #76080

@viceroypenguin

Description

@viceroypenguin

Version Used: Compiler version: '4.12.0-3.24523.4 (f3348c2)'. Language version: latest (13.0).

Steps to Reproduce:

  1. Enable EnforceCodeStyleInBuild
  2. Set AnalysisLevel to latest-all
  3. Use the following code:
#pragma warning disable IDE0008
#pragma warning disable IDE0059

char c = 'x';
bool i = false;

var x = (c, i) switch
{
    ('L', _) => '#',
    ('#', true) => 'L',
    ('#', false) => 'M',
    (var z, _) => z,
};

var y = (c, i) switch
{
    ('L', _) => '#',
    ('#', true) => 'L',
    ('#', false) => 'M',
    (var z, _) => z,
    _ => ' ',
};

Diagnostic Ids: IDE0072 (Populate switch); CS8510 (The pattern is unreachable. It has already been handled by a previous arm of the switch expression or it is impossible to match.)

Expected Behavior:
No diagnostic to be reported on the first switch expression, as it is complete.

Actual Behavior:
IDE0072 is reported on the switch, indicating the analyzer believes that there is a missing branch; however (var z, _) covers all remaining cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-IDEFeature - IDE0072Populate switch expressionhelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions