Skip to content

Conversation

@martin-strecker-sonarsource
Copy link
Contributor

Fixes #9106

@martin-strecker-sonarsource martin-strecker-sonarsource marked this pull request as ready for review June 4, 2024 09:05
Copy link
Contributor

@Tim-Pohlmann Tim-Pohlmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 1 (many more to come!)

|| (parentNode is AssignmentExpressionSyntax assignment && assignment.Left == node)
|| (parentNode is ArgumentSyntax argument && (!argument.RefOrOutKeyword.IsKind(SyntaxKind.None) || TupleExpressionSyntaxWrapper.IsInstance(argument.Parent))))
|| (parentNode is ArgumentSyntax argument && (!argument.RefOrOutKeyword.IsKind(SyntaxKind.None) || TupleExpressionSyntaxWrapper.IsInstance(argument.Parent)))
|| RefExpressionSyntaxWrapper.IsInstance(parentNode))
Copy link
Contributor

@Tim-Pohlmann Tim-Pohlmann Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too simple and introduces an FN (run with C# 9):

    private int _foo; // FN
    public int Foo => _foo;
    void Method()
    {
        _ = ref _foo;
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a FN. If you get a reference to the field, you have write access to it and that write can happen anywhere. This is like calling SomeMethod(ref field) where you do not know what happens inside SomeMethod. We would need to do symbolic execution on the assigned variable to properly detect all scenarios.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you have access to the method where the ref was used. I accept that this is out of the scope of this ticket, but at least add a reproducer to document the limitation.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 4, 2024

Quality Gate Passed Quality Gate passed for 'Sonar .NET Java Plugin'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link
Contributor

@Tim-Pohlmann Tim-Pohlmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvements!

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 4, 2024

@martin-strecker-sonarsource martin-strecker-sonarsource merged commit 778270c into master Jun 4, 2024
@martin-strecker-sonarsource martin-strecker-sonarsource deleted the Martin/S3459_RefProp branch June 4, 2024 14:15
@CristianAmbrosini
Copy link
Contributor

Peach validation
Lost: 12 issues (TN)
Added: /

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix S3459 FP: Backing field with ref property

3 participants