Skip to content

CA1508 is raised incorrectly after a switch expression #53545

@rampaa

Description

@rampaa

Version Used:
Visual Studio 2026 v18.4.1
.NET 9

Steps to Reproduce:

  1. Use the following minimal code sample:
    public static void Test(string? text)
    {
        text = text switch
        {
            "test" => "tesuto",
            _ => text
        };

        if (text?.Length > 2) // CA1508
        {
            Console.WriteLine("Yay!");
        }
    }

Diagnostic Id:

CA1508: Avoid dead conditional code

Expected Behavior:

CA1508 should not get raised incorrectly

Actual Behavior:

CA1508 is being raised incorrectly

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions