You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Version 2.5.0.5410
OS: Microsoft Windows NT 10.0.17134.0, x64
Host Product: Microsoft Office 2016 x64
Host Version: 16.0.4966.1000
Host Executable: EXCEL.EXE
Description
A variable assignment in an error handler is flagged as Not Used, even though that's the Function's "return" variable and it is used in cleaning up the return.
To Reproduce
Public Function Foo() as Long
Dim Sum as Long
On Error Goto ErrorHandler
Sum = 1/0
CleanExit:
Foo = Sum
Exit Function
ErrorHandler:
Sum = -1
Resume CleanExit
End Function
Expected behavior
The Sum = -1 assignment in the ErrorHandler should not be flagged as unused.
There can be a reduction in false positives due to jump statements by evaluating the referenced 'jump-to' labels. If there is a potential of usage in the code below the jump-to label, the unused-assignment-candidate can be removed from the inspection results.
In the same way that ProcedureNotUsedInspection filters all PublicStandard Module procedures from inspection results to avoid false positives - the above approach may avoid some false positives at the potential cost of missing some actual unused assignments. (Granted: the filter applied to ProcedureNotUsedInspection is a more significant 'win')
I have a local branch that accomplishes this. It evaluates Resume and GoTo statements that reference labels or linenumbers. Not included in the evaluation are On...GoTo statements.
I'm commenting here to get some feedback as to whether there is interest in reducing the false positives using this approach before creating a PR.
Rubberduck version information
Description
A variable assignment in an error handler is flagged as
Not Used
, even though that's the Function's "return" variable and it is used in cleaning up the return.To Reproduce
Expected behavior
The
Sum = -1
assignment in the ErrorHandler should not be flagged as unused.Screenshots
N/A
Logfile
RubberduckLog.txt
Additional context
This will probably require full CPA to fix.
The text was updated successfully, but these errors were encountered: