Rubberduck
Rubberduck copied to clipboard
Procedure Not Used Inspection - False Positive
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 Let
ters/Get
ters in the Factory are not flagged, yet used in the same way.
To Reproduce Steps to reproduce the behavior:
- I have no idea how to reproduce it.
Expected behavior
The Let
ter would not be flagged as not used
Screenshots
Logfile RubberduckLog.txt
Additional context Add any other context about the problem here.
Could it be just the With
block throwing a wrench here?
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
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)));
}
This might actually have the same root cause as #5991. I will have a look. Thanks for the MCVE.
For me, the MCVE above does not reproduce the bug. So, I am at a loss here on why that test fails somewhere else.
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.