SonarSource / sonar-dotnet

Code analyzer for C# and VB.NET projects
https://redirect.sonarsource.com/plugins/csharp.html
GNU Lesser General Public License v3.0
797 stars 229 forks source link

Fix S1656 FN: Self-assignment to Me.Field is not detected #9667

Open PavlinII opened 2 months ago

PavlinII commented 2 months ago

S1656 detects useless self-assignment to field, but does not raise when a field is self-assigned using Me. (like this. in C#).

This can help finding bugs in constructors.

Public Class Sample

    Public First, Second As String

    Public Sub New(First As String)
        Me.First = First    'Compliant
        Second = Second     'Noncompliant, as expected
        Me.Second = Second  'False Negative
        Second = Me.Second  'False Negative
    End Sub

End Class
mary-georgiou-sonarsource commented 2 months ago

Dear @PavlinII thanks a lot for reporting this. I confirm it's a False Negative. We'll add it to our backlog and fix it sometime in the future.

@pavel-mikula-sonarsource, our VB.NET expert will be thrilled to fix this.