Skip to content

Commit

Permalink
Fix bug in SyntaxNode::isEquivalentTo
Browse files Browse the repository at this point in the history
  • Loading branch information
MikePopoloski committed Jan 19, 2025
1 parent f8fd13a commit 4bfd8b5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
11 changes: 6 additions & 5 deletions source/syntax/SyntaxNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,13 @@ bool SyntaxNode::isEquivalentTo(const SyntaxNode& other) const {
else {
Token lt = childToken(i);
Token rt = other.childToken(i);

if (!lt)
return !rt;

if (lt.kind != rt.kind || lt.valueText() != rt.valueText())
if (bool(lt) != bool(rt))
return false;

if (lt) {
if (lt.kind != rt.kind || lt.valueText() != rt.valueText())
return false;
}
}
}
return true;
Expand Down
18 changes: 18 additions & 0 deletions tests/unittests/parsing/MemberParsingTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1559,3 +1559,21 @@ endmodule
REQUIRE(diagnostics.size() == 1);
CHECK(diagnostics[0].code == diag::ExpectedToken);
}

TEST_CASE("isEquivalentTo wrong result regress") {
auto& text1 = R"(
module m;
int i = 1;
endmodule
)";
auto& node1 = parseCompilationUnit(text1);

auto& text2 = R"(
module n;
int i = 1;
endmodule
)";
auto& node2 = parseCompilationUnit(text2);

CHECK(!node1.isEquivalentTo(node2));
}

2 comments on commit 4bfd8b5

@MikePopoloski
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@parker-research
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

Please sign in to comment.