Skip to content

Commit 75b5de1

Browse files
committed
Fix NRE in AssignmentNotUsedInspection
The inspection did not consider that the context on module declarations is always null. Now, member variables are ignored because the inspection is rather targeted at local variables.
1 parent a59739a commit 75b5de1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Rubberduck.CodeAnalysis/CodePathAnalysis/Walker.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Collections.Generic;
66
using System.Collections.Immutable;
77
using System.Linq;
8-
using Antlr4.Runtime;
98

109
namespace Rubberduck.Inspections.CodePathAnalysis
1110
{

Rubberduck.CodeAnalysis/Inspections/Concrete/AssignmentNotUsedInspection.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Rubberduck.Parsing.Symbols;
77
using Rubberduck.Inspections.CodePathAnalysis.Extensions;
88
using System.Linq;
9+
using Rubberduck.Inspections.CodePathAnalysis.Nodes;
910
using Rubberduck.Inspections.Results;
1011
using Rubberduck.Parsing;
1112
using Rubberduck.Parsing.Grammar;
@@ -30,7 +31,15 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
3031
var nodes = new List<IdentifierReference>();
3132
foreach (var variable in variables)
3233
{
33-
var tree = _walker.GenerateTree(variable.ParentScopeDeclaration.Context, variable);
34+
var parentScopeDeclaration = variable.ParentScopeDeclaration;
35+
36+
if (parentScopeDeclaration.DeclarationType.HasFlag(DeclarationType.Module))
37+
{
38+
continue;
39+
}
40+
41+
var tree = _walker.GenerateTree(parentScopeDeclaration.Context, variable);
42+
3443

3544
nodes.AddRange(tree.GetIdentifierReferences());
3645
}

0 commit comments

Comments
 (0)