rubberduck-vba / Rubberduck

Every programmer needs a rubberduck. COM add-in for the VBA & VB6 IDE (VBE).
https://rubberduckvba.com
GNU General Public License v3.0
1.92k stars 301 forks source link

Procedure Not Used Inspection False Positive #5490

Closed SmileyFtW closed 4 years ago

SmileyFtW commented 4 years ago

Rubberduck version information Version 2.5.0.5422 OS: Microsoft Windows NT 10.0.18362.0, x64 Host Product: Microsoft Office x86 Host Version: 16.0.12730.20236 Host Executable: EXCEL.EXE

Description Subject Inspection flags a property let accessor as not used when it is used in a factory method

To Reproduce FooModel Class (Predeclared)

Option Explicit
Implements IFoo

Private Type TModel
    SomeProperty As String
End Type
Private this As TModel
Private Property Get IFoo_SomeProperty() As String
    IFoo_SomeProperty = this.SomeProperty
End Property

Public Function Create(ByVal SomeProperty As String) As IFoo
    With New FooModel
        .SomeProperty = SomeProperty 'Let is used here
        Set Create = .Self
    End With
End Function
Public Property Get Self() As IFoo
    Set Self = Me
End Property
Public Property Let SomeProperty(ByVal value As String)
    this.SomeProperty = value
End Property

Expected behavior Inspection would not flag the Let accessor

retailcoder commented 4 years ago

Ha, thanks for that! I did notice this false positive while working on SecureADODB, but then forgot to make an issue for it.

https://github.com/rubberduck-vba/examples/blob/99db9f91bf7094a37783bfcaa743665ffedb6fb0/SecureADODB/AutoDbCommand.cls#L41-L46

SmileyFtW commented 4 years ago

You're most welcome. I am having a great time learning "better coding through RD Inspections".... LOL

SmileyFtW commented 4 years ago

Is this the same thing done differently or a different manifestation?

Private Sub DoBars()
    Dim Bars As Collection
    Set Bars = New Collection

    Dim counter As Long
    Dim currBar As BarModel
    For counter = 1 To 2
        Set currBar = New BarModel
        With currBar
            .ID = "ID" & counter 'False Positive
            Bars.Add currBar, Key:=.ID
        End With
    Next
End Sub