Skip to content
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 S2259 FN: Auto-Properties don't learn ObjectConstraint #6930

Closed
martin-strecker-sonarsource opened this issue Mar 15, 2023 · 2 comments · Fixed by #7007
Closed

Fix S2259 FN: Auto-Properties don't learn ObjectConstraint #6930

martin-strecker-sonarsource opened this issue Mar 15, 2023 · 2 comments · Fixed by #7007
Assignees
Labels
Area: C# C# rules related issues. Area: VB.NET VB.NET rules related issues. Type: False Negative Rule is NOT triggered when it should be.
Milestone

Comments

@martin-strecker-sonarsource
Copy link
Contributor

martin-strecker-sonarsource commented Mar 15, 2023

Instance Fields are tracked by TrackedSymbol while auto-properties are not:

The false negative looks like so:

public object Property { get; set; } // If Property is a field instead, the "Null" constraint is set.

public void M()
{
    Property = null;
    Tag("AfterSetNull", Property); // Auto-property "Property" symbol should have "Null" constraint
    _ = Property.ToString();
    Tag("AfterReadReference", Property);
}

Fix:
Add switch expression case

OperationKindEx.PropertyReference when
    IPropertyReferenceOperationWrapper.FromOperation(operation) is var propertyReference
    && propertyReference.Property.IsAutoProperty()
    && IsStaticOrThis(propertyReference) => propertyReference.Property,

to IOperationExtensions.TrackedSymbol.

@antonioaversa
Copy link
Contributor

It's not clear to me what the automation is doing here:
image

Reassigning @martin-strecker-sonarsource.

@pavel-mikula-sonarsource
Copy link
Contributor

You had to do manual change, because there was probably a rebase conflict and action doesn't trigger. GH already has many people complaining about this.

Then Martin requested your review, so it assigned it to you.

Then you approved it and it assigned it back to Tim because he's the author of the PR. It's not Martin-aware.

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: VB.NET VB.NET rules related issues. Type: False Negative Rule is NOT triggered when it should be.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants