dotnet / dotnet/sdk

CA1508 is raised incorrectly after a switch expression

Open
#53,545 0 comments 0 reactions 0 assignees View on GitHub
Area-Microsoft.CodeAnalysis.NetAnalyzers untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

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

**Steps to Reproduce**:

1. Use the following minimal code sample:
```csharp
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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.