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:
- Compile attached sample:
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<string>? action { get; init; }
public void Indirection()
{
if (action != null)
action("Hello World!");
}
}
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.
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:
repro_CA1508.zip
Diagnostic Id:
CA1508: Avoid dead conditional code
Expected Behavior:
Compile without warning
Actual Behavior:
Warning
This warning is clearly false, since running the application shows that
testValueis not null. The analyzer is not able to see enough about the possibility of modification totestValue.