Skip to content

Commit

Permalink
S1871 Consider variable identity when testing branch equivalence.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasz-tylenda-sonarsource committed Nov 25, 2024
1 parent 8322ed0 commit 20c8c76
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,9 @@ void variablesBoundInInstanceOf() {

Parent p = null;
if (p1 instanceof A a) {
// ^[el=+3;ec=5]> 1 {{Original}}
p = a;
}
else if (p2 instanceof A a) { // Noncompliant {{This branch's code block is the same as the block for the branch on line 234.}}
// ^[el=+3;ec=5]
else if (p2 instanceof A a) {
p = a;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private static IfElseChain collectIdenticalBranches(List<StatementTree> allBranc
for (int j = i + 1; j < allBranches.size(); j++) {
StatementTree statement1 = allBranches.get(i);
StatementTree statement2 = allBranches.get(j);
if (SyntacticEquivalence.areEquivalent(statement1, statement2)) {
if (SyntacticEquivalence.areEquivalentIncludingSameVariables(statement1, statement2)) {
duplicates.add(statement2);
ifElseChain.branches.computeIfAbsent(statement1, k -> new HashSet<>()).add(statement2);
}
Expand Down

0 comments on commit 20c8c76

Please sign in to comment.