Rubberduck: Parameter 'Item' is never used but it is

Created on 21 Oct 2017  Â·  10Comments  Â·  Source: rubberduck-vba/Rubberduck

Warning: Parameter 'Item' is never used - (XLTest163a.xlsm) XLTest.Dictionary, line 43
Public Property Let Item(Key As String, Item As Variant)
AssignKVPValue oKVP, Item

bug feature-inspections

All 10 comments

If you select the Item that's in the method call, does it resolve to the property or to the parameter? If the latter, then it's a resolver bug. If the former, it's an inspection bug.

That said this Item parameter should also trigger a ShadowedDeclaration inspection result. ;-)

Good point about "ShadowedDeclaration" and the parameter/property ambiguity. Given that I want to stick to the existing conventions for naming "Item" as a collection or dictionary item, I'll have to think how to get around that.

@retailcoder The inspection result is not there because someone (😉) changed the severity to DoNotShow and never changed it back.

I just tested this: It resolves to the property:

Public Property Let Item(Key As String, Item As Variant)
    Bar Item
End Property

Public Sub Bar(Foo As Variant)

End Sub

@Hosch250 consider:

Public Property Get Item() As Variant Item = encapsulatedItem End Property

IOW it has to resolve to the property. Better yet:

````
Public Property Let Item(ByVal Item As Variant)
DoSomething Item
End Property

Private Sub DoSomething(ByVal value As Variant)
End Sub
````

If you put the cursor on the Item of the DoSomething Item instruction, and press Shift+F2 (the VBE's "go to declaration" command), you're taken to the Item of Property Let Item, not the parameter.

IOW we're resolving it exactly like the VBE is.

So, this is no bug then. The parameter isn't used.

Except...

Public Property Get Item()
    Item = 12
End Property

Public Property Let Item(ByVal Item As Variant)
    DoSomething Item
End Property

Private Sub DoSomething(ByVal value As Variant)
    Debug.Print value
End Sub

Assuming that's in the code-behind for Sheet1, then running Sheet1.Item = 42 outputs... 42, which means the VBA run-time doesn't agree with the VBE, IOW we have the same bug as the VBE.

We need our resolver to outsmart the VBE here, and prefer the parameter to the procedure's declaration when we're looking at a non-returning member (an Item parameter on an Item returning member would be a duplicate declaration compile-time error anyway)

This code is NOT recursive:

Public Property Let Item(ByVal Item As Variant)
    Static depth As Byte
    depth = depth + 1
    Item = Item * 2
    Debug.Print depth
End Property

My duplicate issue, #3691, has a code example using a string parameter in a class property. Here's a Scripting.Folder example in a Sub. RD 2.1

Variable ‘folderSaveResults’ is not used

Private Sub CreateQueryDebugLog(ByVal strQuery As String)


    Dim FSO As Scripting.FileSystemObject

    Set FSO = New Scripting.FileSystemObject



    Dim folderDebugLog As Scripting.Folder

    Set folderDebugLog = FSO.GetFolder("directorypath")



    If FSO.FolderExists(folderDebugLog.Path) = True Then

        Dim intSystemFileNumber As Integer

        intSystemFileNumber = FreeFile()

        Open folderDebugLog.Path & Application.PathSeparator & "strQuery.txt" For Output As #intSystemFileNumber

        Print #intSystemFileNumber, strQuery

        Close #intSystemFileNumber

    Else

        MsgBox "The default folder for saving a query debug log, " & folderDebugLog.Path & ", cannot be found. Please select a new destination."

        Dim dialogFolderPicker As FileDialog

        Set dialogFolderPicker = Application.FileDialog(msoFileDialogFolderPicker)

        With dialogFolderPicker

            .AllowMultiSelect = False

            .Title = "Select destination folder for Mass Queryer Debug Log"

            .Show

        End With

        Dim folderSaveResults As Scripting.Folder

        Set folderSaveResults = FSO.GetFolder(dialogFolderPicker.SelectedItems.Item(1))

    End If

End Sub

@puzzlepiece87 I'm reviewing this thread and in your code example, you report that the folderSaveResults is reported to be unused. However, in the given sample, this seems correct. You do Set it but you do nothing else with it. Is it missing something?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

addohm picture addohm  Â·  37Comments

ishita799 picture ishita799  Â·  28Comments

ghost picture ghost  Â·  39Comments

bclothier picture bclothier  Â·  33Comments

AndrewM- picture AndrewM-  Â·  37Comments