Rubberduck icon indicating copy to clipboard operation
Rubberduck copied to clipboard

Procedure Not Used Inspection - False Positive

Open SmileyFtW opened this issue 3 years ago • 6 comments

Rubberduck version information Version 2.5.2.5951 OS: Microsoft Windows NT 10.0.19042.0, x64 Host Product: Microsoft Office x86 Host Version: 16.0.14026.20246 Host Executable: EXCEL.EXE

Description From a Factory Method a Let is flagged as not being used when in fact it is. All other Letters/Getters in the Factory are not flagged, yet used in the same way.

To Reproduce Steps to reproduce the behavior:

  1. I have no idea how to reproduce it.

Expected behavior The Letter would not be flagged as not used

Screenshots image image

Logfile RubberduckLog.txt

Additional context Add any other context about the problem here.

SmileyFtW avatar Jun 21 '21 13:06 SmileyFtW

Could it be just the With block throwing a wrench here?

retailcoder avatar Jun 21 '21 19:06 retailcoder

I don’t think so because there are other items in the With block, regardless of Type, that aren’t throwing the exception.

From: Mathieu Guindon @.> Sent: Monday, June 21, 2021 2:44 PM To: rubberduck-vba/Rubberduck @.> Cc: David @.>; Author @.> Subject: Re: [rubberduck-vba/Rubberduck] Procedure Not Used Inspection - False Positive (#5817)

Could it be just the With block throwing a wrench here?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rubberduck-vba/Rubberduck/issues/5817#issuecomment-865296220 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AKCD6F2I3RXLOEXYFBCSCATTT6I6JANCNFSM47BUKIZQ . https://github.com/notifications/beacon/AKCD6F3DKKY4DY2ZPU5YMA3TT6I6JA5CNFSM47BUKIZ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGOJV6XA.gif

SmileyFtW avatar Jun 22 '21 20:06 SmileyFtW

In the process of trying to resolve this one - found that the fundamental issue is that the Parser returns 0 rather than 1 IdentifierReference(s) for Property Let Description in the MCVE below. So, the inspection logic is not the issue, it is correctly evaluating the incorrect data it has received. So, it does seem that the With statement is "throwing a wrench" into this scenario.

Since I steer clear of anything involving the Parser, I'll leave behind the MCVE test code I was using just in case it might save a little bit of time for the next person investigating this one.

[Test]
[Category("Inspections")]
public void MCVE()
{
     var inputCode =
$@"
Option Explicit

Private Type T{MockVbeBuilder.TestModuleName}
    Description As String
End Type

Private this As T{MockVbeBuilder.TestModuleName}

Public Function Create(ByVal pArg As String) As {MockVbeBuilder.TestModuleName}
    Dim tm As {MockVbeBuilder.TestModuleName}
    Set tm = New {MockVbeBuilder.TestModuleName}
    With tm 
        .Description = pArg
    End With
    Set Create = tm 
End Function

Public Property Let Description(ByVal RHS As String)
    this.Description = RHS
End Property
";

     var modules = new (string, string, ComponentType)[]
     {
            (MockVbeBuilder.TestModuleName, inputCode, ComponentType.ClassModule),
     };

     var results = InspectionResultsForModules(modules);

     Assert.AreEqual(0, InspectionResultsForModules(modules).Count(result=>
         result.Target.DeclarationType.HasFlag(DeclarationType.PropertyLet)));
}

BZngr avatar Oct 05 '22 03:10 BZngr

This might actually have the same root cause as #5991. I will have a look. Thanks for the MCVE.

MDoerner avatar Oct 05 '22 19:10 MDoerner

For me, the MCVE above does not reproduce the bug. So, I am at a loss here on why that test fails somewhere else.

MDoerner avatar Oct 07 '22 12:10 MDoerner

Welp...I too am at a loss. I've just re-run the MCVE both as a VS test and as code in Excel...with no inspection result! It was very repeatable when I commented 2 days ago.

BZngr avatar Oct 07 '22 13:10 BZngr