-
Notifications
You must be signed in to change notification settings - Fork 222
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 FP S2589: Assignment for captures are ignored #9204
Labels
Area: C#
C# rules related issues.
Area: CFG/SE
CFG and SE related issues.
Type: False Positive
Rule IS triggered when it shouldn't be.
Comments
martin-strecker-sonarsource
added
Type: False Positive
Rule IS triggered when it shouldn't be.
Area: CFG/SE
CFG and SE related issues.
Area: C#
C# rules related issues.
labels
Apr 25, 2024
Possible solutionsInvocation unrollingSee https://trello.com/c/dELDhBru Ignoring captured and mutated symbols after their capturing
Ignoring captured and mutated symbols completely
public bool SelectTest(List<string> licenseData)
{
bool found;
var qry = licenseData.Select(license => found = true)
found = false;
qry.Any(); // This evaluates the lambda and maybe sets true. This is hard to predict because the lambda cfg is visited before the found = false
if (!found) // Noncompliant FP
{
Console.WriteLine("No License for artifact type");
}
return found;
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Area: C#
C# rules related issues.
Area: CFG/SE
CFG and SE related issues.
Type: False Positive
Rule IS triggered when it shouldn't be.
Originally reported at https://community.sonarsource.com/t/false-positive-for-s2589/114185
Description
Any mutation of a captured variable is ignored. This applies to captures by delegates and by local functions. See also #8885
Repro steps
Expected behavior
Do not raise on mutated captured variables or learn inside the delegate/local function body.
Actual behavior
FP for S2589
Known workarounds
Do not mutate capture variables.
The text was updated successfully, but these errors were encountered: