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.95k stars 4.02k forks source link

Using-declaration should not trigger RemoveUnusedValues #33464

Closed jcouv closed 5 years ago

jcouv commented 5 years ago

I suspect this is a compiler issue, as the AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer relies on the control flow graph to determine how variables are used.

image

image

FYI @mavasani

mavasani commented 5 years ago

Thanks @jcouv. This seems to be same as https://github.com/dotnet/csharplang/issues/2235#issuecomment-464308801. Current IOperation tree and ControlFlowGraph have no special operation node for using declaration, it is just an Operation.None node wrapping the variable declaration. This leads to all CFG and IOperation clients that attempt to analyze reads and writes to see a variable declaration, whose underlying declared local is never referenced. I believe this issue will get fixed once we implement IOperation and CFG support for this feature.

chsienki commented 5 years ago

We have an open issue on this https://github.com/dotnet/roslyn/issues/32100 which should fix once implemented.

jcouv commented 5 years ago

Closed as dupe of https://github.com/dotnet/roslyn/issues/32100. Copied scenario details over there