Skip to content

Fix copy-paste bugs in DataflowAnalyzer equality checks#44572

Open
marzi3 wants to merge 1 commit into
ballerina-platform:masterfrom
marzi3:fix/dataflow-analyzer-copy-paste-bugs
Open

Fix copy-paste bugs in DataflowAnalyzer equality checks#44572
marzi3 wants to merge 1 commit into
ballerina-platform:masterfrom
marzi3:fix/dataflow-analyzer-copy-paste-bugs

Conversation

@marzi3
Copy link
Copy Markdown

@marzi3 marzi3 commented Apr 26, 2026

Purpose

Fixes #44571

Two equality checks in DataflowAnalyzer.java incorrectly compared nodeA with itself, causing the XML_QNAME and GROUP_EXPR checks to always return true. This PR corrects them to compare nodeA with nodeB.

Approach

  • Line 1270 (XML_QNAME): nodeA == nodeAnodeA == nodeB
  • Line 1393 (GROUP_EXPR): nodeA == nodeAnodeA == nodeB

Check List

  • Read the Contributing Guide
  • Updated Change Log
  • Checked Tooling Support (#)
  • Added necessary tests
    • Unit Tests
    • Spec Conformance Tests
    • Integration Tests
    • Ballerina By Example Tests
  • Increased Test Coverage
  • Added necessary documentation
    • API documentation
    • Module documentation in Module.md files
    • Ballerina By Examples

Summary

This pull request corrects two copy-paste errors in the DataflowAnalyzer.java equality comparison method where the second operand of the comparison was incorrectly referencing the first operand instead of the intended second operand.

The fixes ensure that equality checks for XML_QNAME and GROUP_EXPR node types properly compare both operands as intended, rather than comparing each operand against itself. This improves the correctness and reliability of the dataflow analysis by ensuring equality comparisons work as designed.

Changes made:

  • Line 1270 (XML_QNAME case): Corrected the second variable cast to use nodeB instead of nodeA
  • Line 1393 (GROUP_EXPR case): Corrected the second variable cast to use nodeB instead of nodeA

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 26, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 26, 2026

📝 Walkthrough

Walkthrough

Corrects two copy-paste bugs in the equality(Node nodeA, Node nodeB) method where nodeA was incorrectly reused instead of using nodeB for type casting in XML_QNAME and GROUP_EXPR node comparisons, ensuring both operands are properly compared.

Changes

Cohort / File(s) Summary
DataflowAnalyzer equality fix
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DataflowAnalyzer.java
Fixed copy-paste bugs on lines 1270 and 1393 where nodeA was incorrectly cast for the second operand (xmlqNameB and groupExprB); changed to use nodeB for proper comparison logic.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 Two little copy-paste blunders found,
Where nodeA danced where nodeB should bound,
Now equality checks both sides with care,
The bugs are fixed—a comparison so fair! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing copy-paste bugs in equality checks within DataflowAnalyzer.
Description check ✅ Passed The description covers Purpose, Approach, and a partial Checklist but lacks Samples and Remarks sections from the template.
Linked Issues check ✅ Passed The PR correctly addresses both bugs in issue #44571: correcting the nodeA/nodeB casts in XML_QNAME (line 1270) and GROUP_EXPR (line 1393) cases.
Out of Scope Changes check ✅ Passed All changes are directly aligned with the bug fix objective; only two lines corrected in the equality method with no extraneous modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DataflowAnalyzer.java (1)

1393-1393: Correct fix for GROUP_EXPR equality.

Casting nodeB here ensures equality(groupExprA.expression, groupExprB.expression) recurses into both operands rather than comparing nodeA with itself. Consistent with the TYPE_CONVERSION_EXPR/UNARY_EXPR cases above.

A small follow-up worth considering (out of scope for this PR): adding a regression test under the dataflow analyzer test suite that constructs a table literal with two records whose keys differ only inside an XML_QNAME or GROUP_EXPR subexpression, to lock in this behavior and prevent re-introduction.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DataflowAnalyzer.java`
at line 1393, The GROUP_EXPR branch in DataflowAnalyzer's equality logic
incorrectly compares the node to itself; cast nodeB to BLangGroupExpr
(BLangGroupExpr groupExprB = (BLangGroupExpr) nodeB) and call
equality(groupExprA.expression, groupExprB.expression) so the comparison
recurses into the two operands correctly (mirroring the
TYPE_CONVERSION_EXPR/UNARY_EXPR cases).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DataflowAnalyzer.java`:
- Line 1393: The GROUP_EXPR branch in DataflowAnalyzer's equality logic
incorrectly compares the node to itself; cast nodeB to BLangGroupExpr
(BLangGroupExpr groupExprB = (BLangGroupExpr) nodeB) and call
equality(groupExprA.expression, groupExprB.expression) so the comparison
recurses into the two operands correctly (mirroring the
TYPE_CONVERSION_EXPR/UNARY_EXPR cases).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4559aff9-18dd-49c8-9569-709ec9d99d77

📥 Commits

Reviewing files that changed from the base of the PR and between f59068a and 847ea85.

📒 Files selected for processing (1)
  • compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DataflowAnalyzer.java

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.02%. Comparing base (3211861) to head (847ea85).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #44572      +/-   ##
============================================
- Coverage     75.03%   75.02%   -0.01%     
  Complexity    58707    58707              
============================================
  Files          3601     3601              
  Lines        227161   227161              
  Branches      29581    29581              
============================================
- Hits         170443   170437       -6     
- Misses        47215    47217       +2     
- Partials       9503     9507       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Copy-paste bugs in DataflowAnalyzer equality check

2 participants