You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please provide a succinct description of your issue. Also please provide the rule ID (e.g. S1234)
Repro steps
privatestaticvoidFoo(){string?one=null;string?two=null;varvalues=newList<string>{"one","two"};foreach(varvalueinvalues){switch(value){case"one":one=value;break;case"two":two=value;break;}}if(string.IsNullOrEmpty(one)){Console.WriteLine("one");return;}// Change this condition so that it does not always evaluate to 'True'. Some code paths are unreachable. if(string.IsNullOrEmpty(two)){Console.WriteLine("two");}}
Expected behavior
No false-positive as variable two can be null if it doesn't hit the switch case.
Actual behavior
A false-positive is reported.
Known workarounds
Instead of declaring the two variables as string?, use string.Empty.
varone=string.Empty;vartwo=string.Empty;
Related information
SonarQube connected mode with VS2022
The text was updated successfully, but these errors were encountered:
antonioaversa
changed the title
Fix S2583 FP/FN: Wrong evaluation in switch-case assignment
Fix S2583 FP: Wrong evaluation in switch-case assignment
Feb 12, 2024
Hello @4865783a5d, I cannot reproduce the issue. Which version of the analyzer are you using?
Anyway, if you still have the issue, there is a good chance it is connected to #8474 which will be fixed in 9.20.
Description
Please provide a succinct description of your issue. Also please provide the rule ID (e.g. S1234)
Repro steps
Expected behavior
No false-positive as variable two can be null if it doesn't hit the switch case.
Actual behavior
A false-positive is reported.
Known workarounds
Instead of declaring the two variables as string?, use string.Empty.
Related information
SonarQube connected mode with VS2022
The text was updated successfully, but these errors were encountered: