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

Fix S4275 VB .NET : FP when `WithEvents` is present #2774

Closed andrei-epure-sonarsource closed 4 years ago

andrei-epure-sonarsource commented 4 years ago

Description

from community

Repro steps

    Public Class Class1
        Private Withevents _cashLess as CashLess

        Public Property CashLess() As CashLess
            Get ' Noncompliant FP
                Return _cashLess
            End Get
            Set(ByVal value As CashLess) ' Noncompliant FP
                _cashLess = value
            End Set
        End Property

    End Class

Expected behavior

Should not raise FP

Actual behavior

Raises FP

Known workarounds

Remove Withevents

Related information

pavel-mikula-sonarsource commented 4 years ago

Background info: VB.NET compiler adds _XXX backing field for XXX WithEvents variable (therefore __cashLess) in order to deal with automatic AddHandler/RemoveHandler for Handles syntax.