CA1508 is triggered despite value being set
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 1.3k
- PR merge metrics
- PR metrics pending
Description
**Version Used**:
.NET SDK:
Version: 10.0.100-rc.2.25462.101
Commit: 26861c107e
Workload version: 10.0.100-manifests.663d2eb1
MSBuild version: 17.15.0-preview-25462-101+26861c107
**Steps to Reproduce**:
1. Compile attached sample:
```c#
string? testValue = null;
var class2 = new Class2
{
action = (value) => testValue = value
};
class2.Indirection();
if (testValue != null)
{
// Do something
Console.WriteLine(testValue);
}
public class Class2()
{
public Action? action { get; init; }
public void Indirection()
{
if (action != null)
action("Hello World!");
}
}
```
[repro_CA1508.zip](https://github.com/user-attachments/files/22481800/repro_CA1508.zip)
**Diagnostic Id**:
CA1508: Avoid dead conditional code
**Expected Behavior**:
Compile without warning
**Actual Behavior**:
Warning
```
warning CA1508: 'testValue != null' is always 'false'. Remove or refactor the condition(s) to avoid dead code. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1508)
```
This warning is clearly false, since running the application shows that `testValue` is not null. The analyzer is not able to see enough about the possibility of modification to `testValue`.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.