Skip to content

Commit d5a5587

Browse files
authored
Merge pull request #5541 from BZngr/UnusedAssignment_FalsePositives
AssignmentNotUsedInspection false positives - incorrect variable scoping and others
2 parents 9ed85e0 + bb1b1dd commit d5a5587

File tree

6 files changed

+487
-175
lines changed

6 files changed

+487
-175
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ CodeGraphData/
186186

187187
# Generated Artifacts
188188
Rubberduck.CodeAnalysis.xml
189+
Rubberduck.Parsing.xml
189190

190191
#Gradle
191192
/.gradle/

Rubberduck.CodeAnalysis/CodePathAnalysis/Extensions/NodeExtensions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,21 @@ public static INode GetFirstNode(this INode node, ICollection<Type> excludedType
5555

5656
return GetFirstNode(node.Children[0], excludedTypes);
5757
}
58+
59+
public static bool TryGetAncestorNode<T>(this INode node, out T ancestor) where T: INode
60+
{
61+
ancestor = default;
62+
if (node.Parent is null)
63+
{
64+
return false;
65+
}
66+
67+
if (node.Parent is T result)
68+
{
69+
ancestor = result;
70+
return true;
71+
}
72+
return TryGetAncestorNode(node.Parent, out ancestor);
73+
}
5874
}
5975
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Antlr4.Runtime.Tree;
2+
3+
namespace Rubberduck.Inspections.CodePathAnalysis.Nodes
4+
{
5+
public class AssignmentExpressionNode : NodeBase
6+
{
7+
public AssignmentExpressionNode(IParseTree tree) : base(tree) { }
8+
}
9+
}

Rubberduck.CodeAnalysis/CodePathAnalysis/Walker.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public INode GenerateTree(IParseTree tree, Declaration declaration)
3333
case VBAParser.BlockContext _:
3434
node = new BlockNode(tree);
3535
break;
36+
case VBAParser.LetStmtContext _:
37+
case VBAParser.SetStmtContext _:
38+
node = new AssignmentExpressionNode(tree);
39+
break;
3640
}
3741

3842
if (declaration.Context == tree)

0 commit comments

Comments
 (0)