False positive IDE0010 on exhaustive pattern matching in switch statement
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
**Version Used**: Visual Studio Community 2026 18.7.3
**Steps to Reproduce**:
1. Create new project
2. Add the sample code
``` c#
public class Test where T : class {
public void Foo() {
T? obj = null;
switch (obj) {
case null:
break;
case not null:
break;
}
}
}
```
Note that `T` can be replaced with any type that can be instantiated or any constrained generic type that allows `null` conversion.
**Diagnostic Id**:
IDE0010: 填充开关
**Expected Behavior**:
The analyzer should recognize that null and not null cover 100% of the input domain, and therefore IDE0010 should not be reported.
**Actual Behavior**:
The IDE0010 diagonolosis is reported.
When apply automatic fix (Add default case), `default:` case is added and CS0162 is reported, proving that the compiler already considers the switch statement exhaustive, whereas the IDE analyzer does not.
Contributor guide
Research direction
Start by reproducing the sample generic switch in a C# project and inspect the IDE0010 analyzer and its automatic default-case fix. Done means the analyzer recognizes null and not-null as exhaustive, no IDE0010 diagnostic appears, and the fix no longer adds an unreachable default case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- compilers, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100