Skip to content

Commit b8a7190

Browse files
committed
fixes #2620
1 parent 7bbf74b commit b8a7190

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Rubberduck.Parsing/Symbols/BoundExpressionVisitor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Rubberduck.Parsing.Annotations;
22
using Rubberduck.Parsing.Binding;
3+
using Rubberduck.Parsing.Grammar;
34
using Rubberduck.VBEditor;
45

56
namespace Rubberduck.Parsing.Symbols
@@ -47,6 +48,12 @@ private void Visit(
4748
bool isAssignmentTarget,
4849
bool hasExplicitLetStatement)
4950
{
51+
if (isAssignmentTarget && expression.Context.Parent is VBAParser.IndexExprContext)
52+
{
53+
// 'SomeDictionary' is not the assignment target in 'SomeDictionary("key") = 42'
54+
isAssignmentTarget = false;
55+
}
56+
5057
var callSiteContext = expression.Context;
5158
var identifier = expression.Context.GetText();
5259
var callee = expression.ReferencedDeclaration;

RubberduckTests/Inspections/ObjectVariableNotSetInpsectionTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,34 @@ namespace RubberduckTests.Inspections
1616
[TestClass]
1717
public class ObjectVariableNotSetInpsectionTests
1818
{
19+
[TestMethod]
20+
[TestCategory("Inspections")]
21+
public void ObjectVariableNotSet_GivenIndexerObjectAccess_ReturnsNoResult()
22+
{
23+
const string inputCode = @"
24+
Private Sub DoSomething()
25+
Dim target As Object
26+
Set target = CreateObject(""Scripting.Dictionary"")
27+
target(""foo"") = 42
28+
End Sub
29+
";
30+
//Arrange
31+
var builder = new MockVbeBuilder();
32+
IVBComponent component;
33+
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
34+
var mockHost = new Mock<IHostApplication>();
35+
mockHost.SetupAllProperties();
36+
var parser = MockParser.Create(vbe.Object, new RubberduckParserState(vbe.Object));
37+
38+
parser.Parse(new CancellationTokenSource());
39+
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
40+
41+
var inspection = new ObjectVariableNotSetInspection(parser.State);
42+
var inspectionResults = inspection.GetInspectionResults();
43+
44+
Assert.AreEqual(0, inspectionResults.Count());
45+
}
46+
1947
[TestMethod]
2048
[TestCategory("Inspections")]
2149
public void ObjectVariableNotSet_GivenStringVariable_ReturnsNoResult()

0 commit comments

Comments
 (0)