Skip to content

Conversation

@MDoerner
Copy link
Contributor

Closes #5845

This inspection usually ignores arrays because they are technically valid without assignment. Moreover, it is a bit unclear what it means for them not to be assigned. (one index vs. all indices)

In the case of a Variant used as an array without an assignment to it, which is possible using a ReDim statement, we do not know that the variable represents an array. So, an inspection result was issued, although some or all array slots were assigned to.

To deal with this, a new property IsReDim has been introduced on the IdentifierReference that stores whether this reference is the array reference in a ReDim statement; it is set in the resolver.
Whenever we see such a reference on a Variant, we can be sure that it is used as an array at some point. In a sense, the ReDim statement assigns a new array to the Variant.

This inspection usually ignores arrays because they are technically valid without assignment. Moreover, it is a bit unclear what it means for them not to be assigned. (one index vs. all indices)

In the case of a Variant used as an array without an assignment to it, which is possible using a ReDim statement, we do not know that the variable represents an array. So, an inspection result was issued, although some or all array slots were assigned to.

To deal with this, a new property IsReDim has been introduced on the IdentifierReference that stores whether this reference is the array reference in a ReDim statement; it is set in the resolver.
Whenever we see such a reference on a Variant, we can be sure that it is used as an array at some point. In a sense, the ReDim statement assigns a new array to the Variant.
@MDoerner MDoerner added the hacktoberfest-accepted Thank you! Get that t-shirt! label Oct 3, 2021
@retailcoder retailcoder merged commit 2039bbf into rubberduck-vba:next Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hacktoberfest-accepted Thank you! Get that t-shirt!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code Inspection: Variable not assigned when Variant used as Array

3 participants