-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix S2583 FP: Issue is raised when there is comparison to a constant. #8080
Comments
It wasn't exclusively constants in my testing, it was any variable defined outside of the method. |
This is a symbolic execution rule. In this context, the symbolic execution engine tracks const members and their values, so it should know that In the case of nonconstant class members, their value is not tracked and the engine tries to learn number constraints from the context (just like they are parameters to the method, try to give |
Interesting, thanks for your explanation. |
I am running into something very similar: static bool Foo(string? someText)
{
var parts = someText.Replace("F#3=", string.Empty).Replace("\r\n", string.Empty).Split(',');
if (parts.Length != 5)
{
return false;
}
for (var i = 0; i < parts.Length; i++)
{
switch (i)
{
case 0:
DoSomething();
break;
case 1: // raises S2583 , considering this condition always true
DoSomething();
break;
case 2:
DoSomething();
break;
case 3:
DoSomething();
break;
}
}
return true;
} Is this the same issue as mentioned above? |
@steven-forrrest-vincit This is a different issue. It is caused by the Symbolic Execution engine exploring loops only for two iterations. |
Okay, will this issue be fixed in a future update? |
The issue could be fixed in multiple ways.
|
Repro steps
When the
Limit
is declared locally, no issue is raised.It seems that there's some issue with learning numerical constraints for constants.
The issue has been reported by a community post.
The text was updated successfully, but these errors were encountered: