Skip to content

Commit c0c83e4

Browse files
committed
Stop considering index expressions on Variants as default member accesses
They might as well be array accesses. Now, no references will be generated for these anymore.
1 parent e98ab4d commit c0c83e4

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

Rubberduck.Parsing/Binding/Bindings/IndexDefaultBinding.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,21 @@ private IBoundExpression ResolveDefaultMember(string asTypeName, Declaration asT
298298
named arguments. In this case, the index expression is classified as an unbound member with
299299
a declared type of Variant, referencing <l-expression> with no member name.
300300
*/
301-
if (
302-
(Tokens.Variant.Equals(asTypeName, StringComparison.InvariantCultureIgnoreCase)
303-
|| Tokens.Object.Equals(asTypeName, StringComparison.InvariantCultureIgnoreCase))
301+
if (Tokens.Variant.Equals(asTypeName, StringComparison.InvariantCultureIgnoreCase)
302+
&& !argumentList.HasNamedArguments)
303+
{
304+
ResolveArgumentList(null, argumentList);
305+
//We do not treat unbound accesses on variables of type Variant as default member accesses because they could be array accesses as well.
306+
return new IndexExpression(null, ExpressionClassification.Unbound, expression, _lExpression, argumentList, isDefaultMemberAccess: false, defaultMemberRecursionDepth: defaultMemberResolutionRecursionDepth, containedDefaultMemberRecursionExpression: containedExpression);
307+
}
308+
309+
if (Tokens.Object.Equals(asTypeName, StringComparison.InvariantCultureIgnoreCase)
304310
&& !argumentList.HasNamedArguments)
305311
{
306312
ResolveArgumentList(null, argumentList);
307313
return new IndexExpression(null, ExpressionClassification.Unbound, expression, _lExpression, argumentList, isDefaultMemberAccess: true, defaultMemberRecursionDepth: defaultMemberResolutionRecursionDepth, containedDefaultMemberRecursionExpression: containedExpression);
308314
}
315+
309316
/*
310317
The declared type of <l-expression> is a specific class, which has a public default Property
311318
Get, Property Let, function or subroutine, and one of the following is true:

Rubberduck.Parsing/VBA/ReferenceManagement/BoundExpressionVisitor.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ private void Visit(
250250
Visit(expression.LExpression, module, scope, parent, hasExplicitLetStatement: hasExplicitLetStatement);
251251
AddArrayAccessReference(expression, module, scope, parent, isAssignmentTarget, hasExplicitLetStatement, isSetAssignment);
252252
}
253+
else if (expression.Classification == ExpressionClassification.Unbound
254+
&& expression.ReferencedDeclaration == null)
255+
{
256+
Visit(expression.LExpression, module, scope, parent);
257+
}
253258
else
254259
{
255260
// Index expressions are a bit special in that they can refer to parameterized properties and functions.

RubberduckTests/Inspections/IndexedUnboundDefaultMemberAccessInspectionTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,26 @@ End Function
184184
Assert.AreEqual(1, inspectionResults.Count());
185185
}
186186

187+
[Test]
188+
[Category("Inspections")]
189+
public void JaggedArray_NoResult()
190+
{
191+
var moduleCode = @"
192+
Private Function Foo() As Variant
193+
Dim outerArray() As Variant
194+
Dim firstInnerArray() As Variant
195+
Dim secondInnerArray() As Variant
196+
outerArray = Array(firstInnerArray, secondInnerArray)
197+
Foo = outerArray(0)(0)
198+
End Function
199+
";
200+
201+
var inspectionResults = InspectionResultsForStandardModule(moduleCode);
202+
203+
Assert.AreEqual(0, inspectionResults.Count());
204+
}
205+
206+
187207
protected override IInspection InspectionUnderTest(RubberduckParserState state)
188208
{
189209
return new IndexedUnboundDefaultMemberAccessInspection(state);

0 commit comments

Comments
 (0)