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
786 stars 226 forks source link

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

Open PavlinII opened 3 weeks ago

PavlinII commented 3 weeks 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 3 weeks 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.