dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.71k stars 3.98k forks source link

Missing 'unnecessary assignment of a value' diagnostic #59525

Open Youssef1313 opened 2 years ago

Youssef1313 commented 2 years ago

Version Used:

Steps to Reproduce:

public class A
{
    public C B { get; }
}

public class C
{
    public void M(object x)
    {
        if (x is A { B: C c } a) { }
    }
}

Expected Behavior:

Both a and c are faded out.

Actual Behavior:

Only c is faded out.

image

RikkiGibson commented 2 years ago

curious if this is due to behavior of the data flow APIs or the way the APIs are being used.

mavasani commented 2 years ago

Note this analyzer does not use compiler’s dataflow APIs. It uses the control flow graph API and performs custom dataflow analysis on the exposed CFG.