Version 2.4.1.4627
OS: Microsoft Windows NT 6.2.9200.0, x64
Host Product: Microsoft Office 2010 x86
Host Version: 14.0.7232.5000
Host Executable: EXCEL.EXE
Description
When running code review, certain variables get marked as 'Assignment not in use' when this is not true.
To Reproduce
Expected behavior
The code above sets the range to a specific place and then uses that to offset it's location to get a more precise subset of data. The Table variable gets marked as Assignment unused, when in fact it is being used in the very next line in order to get better precision.
Additional context
I feel as though the code inspection is trying to see if a variable gets assigned and then if the variable gets assigned right away before being used, but it should also look that if it is being assigned again whether it is also part of the assignment.
Makes sense to mark this as assignment unused
X = A
X = B
Doesn't make sense to mark this as assignment unused
X = A
X = X.Offset(B)
Repro confirmed. The good news is that the resolver correctly picks up every single part of the RHS expression in the provided example, so this shouldn't be too hard to fix:
I think all we need to do is to rewrite that LINQ query so that we keep r.Context.Parent is VBAParser.SetStmtContext setStmtContext around for further querying, and discard the IdentifierReference when the RHS of setStmtContext contains one or more identifier references for the variable.
Thanks for reporting this.
This seems to essentially be a duplicate of #4913.
hmm, it's not just SetStmtContext, we need to also check for LetStmtContext. Indeed a duplicate.
Sorry for the duplication; thank you for the quick turnaround!
Most helpful comment
Thanks for reporting this.
This seems to essentially be a duplicate of #4913.