Closed hugoqribeiro closed 2 months ago
Thank you for reporting this. Confirmed as a bug.
The analyzer fails when it reaches the nameof(this.VerificationCode)
and tries to resolve it as a symbol. But Roslyn treats the nameof
expression as a compile-time constant, and it returns null for a symbol, which isn't handled correctly by the analyzer.
A shorter reproducer looks like this:
public string NameOfWithSameVariable(string str)
{
if (str.Length == 42)
{
var ret = nameof(str); // <--- AD0001
return ret;
}
else if (str.Length == 43)
{
var ret = nameof(str);
return ret;
}
return "";
}
Description
Compiling a solution raises the following warning:
Repro steps
I think the method being analyzed is this one:
Known workarounds
N/A
Related information
Visual Studio 17.10.5 SonarAnalyzer.CSharp 9.30.0.95878