File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Rubberduck.Parsing/Symbols
RubberduckTests/Inspections Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1
1
using Rubberduck . Parsing . Annotations ;
2
2
using Rubberduck . Parsing . Binding ;
3
+ using Rubberduck . Parsing . Grammar ;
3
4
using Rubberduck . VBEditor ;
4
5
5
6
namespace Rubberduck . Parsing . Symbols
@@ -47,6 +48,12 @@ private void Visit(
47
48
bool isAssignmentTarget ,
48
49
bool hasExplicitLetStatement )
49
50
{
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
+
50
57
var callSiteContext = expression . Context ;
51
58
var identifier = expression . Context . GetText ( ) ;
52
59
var callee = expression . ReferencedDeclaration ;
Original file line number Diff line number Diff line change @@ -16,6 +16,34 @@ namespace RubberduckTests.Inspections
16
16
[ TestClass ]
17
17
public class ObjectVariableNotSetInpsectionTests
18
18
{
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
+
19
47
[ TestMethod ]
20
48
[ TestCategory ( "Inspections" ) ]
21
49
public void ObjectVariableNotSet_GivenStringVariable_ReturnsNoResult ( )
You can’t perform that action at this time.
0 commit comments