Skip to content

FIX: ArrayHelpers.Merge used the comparer incorrectly [ISXB-1790]#2377

Merged
K-Tone merged 5 commits intodevelopfrom
fix/ISXB-1790-array-helpers-merge-comparer
Mar 27, 2026
Merged

FIX: ArrayHelpers.Merge used the comparer incorrectly [ISXB-1790]#2377
K-Tone merged 5 commits intodevelopfrom
fix/ISXB-1790-array-helpers-merge-comparer

Conversation

@K-Tone
Copy link
Copy Markdown
Collaborator

@K-Tone K-Tone commented Mar 12, 2026

Description

Practically, our ArrayHelpers.Merge implementation doesn't use the supplied comparer to compare elements when merging, instead it will search for comparer in the second array. That's clearly wrong. Fixed that, and also a few other things as we go, added some new test coverage.

Made-with: Cursor

Testing status & QA

Local testing, CI run pending

Overall Product Risks

  • Complexity: Low
  • Halo Effect: Low

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • JIRA ticket linked, example (case %%). If it is a private issue, just add the case ID without a link.
    • Jira port for the next release set as "Resolved".
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

…s arguments

- comparer.Equals(secondValue) was comparing against comparer instance.
- Use comparer.Equals(x, secondValue) to check if any merged element x equals secondValue.
- Add Utilities_MergeWithComparer_UsesComparerToDeduplicate test.

Made-with: Cursor
Copy link
Copy Markdown
Contributor

@u-pr u-pr bot left a comment

Choose a reason for hiding this comment

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

May require changes

The review identified a high-importance logic bug where the index parameter is ignored in HaveDuplicateReferences, potentially leading to incorrect results for sub-range checks. Additionally, there is a medium-importance performance concern regarding heap allocations in the Merge method and a low-importance suggestion for type constraints to prevent boxing.

🤖 Helpful? 👍/👎

@codecov-github-com
Copy link
Copy Markdown

codecov-github-com bot commented Mar 12, 2026

Codecov Report

All modified and coverable lines are covered by tests ✅

@@             Coverage Diff             @@
##           develop    #2377      +/-   ##
===========================================
+ Coverage    77.92%   78.11%   +0.19%     
===========================================
  Files          482      483       +1     
  Lines        97755    98784    +1029     
===========================================
+ Hits         76175    77170     +995     
- Misses       21580    21614      +34     
Flag Coverage Δ
inputsystem_MacOS_2022.3 5.34% <0.00%> (-0.22%) ⬇️
inputsystem_MacOS_2022.3_project 75.32% <100.00%> (-0.05%) ⬇️
inputsystem_MacOS_6000.0 5.31% <0.00%> (-0.03%) ⬇️
inputsystem_MacOS_6000.0_project 77.22% <100.00%> (-0.05%) ⬇️
inputsystem_MacOS_6000.3 5.31% <0.00%> (-0.03%) ⬇️
inputsystem_MacOS_6000.3_project 77.21% <100.00%> (-0.06%) ⬇️
inputsystem_MacOS_6000.4 5.31% <0.00%> (-0.03%) ⬇️
inputsystem_MacOS_6000.4_project 77.22% <100.00%> (-0.06%) ⬇️
inputsystem_MacOS_6000.5 5.30% <0.00%> (-0.04%) ⬇️
inputsystem_MacOS_6000.5_project 77.26% <100.00%> (-0.02%) ⬇️
inputsystem_MacOS_6000.6 5.30% <0.00%> (-0.04%) ⬇️
inputsystem_MacOS_6000.6_project 77.25% <100.00%> (-0.03%) ⬇️
inputsystem_Ubuntu_2022.3_project 75.22% <100.00%> (+0.05%) ⬆️
inputsystem_Ubuntu_6000.0 5.31% <0.00%> (-0.03%) ⬇️
inputsystem_Ubuntu_6000.0_project 77.13% <100.00%> (+0.06%) ⬆️
inputsystem_Ubuntu_6000.3 5.31% <0.00%> (-0.03%) ⬇️
inputsystem_Ubuntu_6000.3_project 77.12% <100.00%> (+0.04%) ⬆️
inputsystem_Ubuntu_6000.4 5.32% <0.00%> (-0.03%) ⬇️
inputsystem_Ubuntu_6000.4_project 77.13% <100.00%> (+0.04%) ⬆️
inputsystem_Ubuntu_6000.5 5.31% <0.00%> (-0.04%) ⬇️
inputsystem_Ubuntu_6000.5_project 77.16% <100.00%> (+0.07%) ⬆️
inputsystem_Ubuntu_6000.6 5.31% <0.00%> (-0.04%) ⬇️
inputsystem_Ubuntu_6000.6_project 77.16% <100.00%> (+0.08%) ⬆️
inputsystem_Windows_2022.3 5.34% <0.00%> (-0.22%) ⬇️
inputsystem_Windows_2022.3_project 75.45% <100.00%> (-0.04%) ⬇️
inputsystem_Windows_6000.0 5.31% <0.00%> (-0.03%) ⬇️
inputsystem_Windows_6000.0_project 77.34% <100.00%> (-0.05%) ⬇️
inputsystem_Windows_6000.3 5.31% <0.00%> (-0.03%) ⬇️
inputsystem_Windows_6000.3_project 77.34% <100.00%> (-0.05%) ⬇️
inputsystem_Windows_6000.4 5.31% <0.00%> (-0.03%) ⬇️
inputsystem_Windows_6000.4_project 77.35% <100.00%> (-0.05%) ⬇️
inputsystem_Windows_6000.5 5.30% <0.00%> (-0.04%) ⬇️
inputsystem_Windows_6000.5_project 77.39% <100.00%> (-0.01%) ⬇️
inputsystem_Windows_6000.6 5.30% <0.00%> (-0.04%) ⬇️
inputsystem_Windows_6000.6_project 77.39% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ts/Tests/InputSystem/Utilities/ArrayHelperTests.cs 100.00% <100.00%> (ø)
....inputsystem/InputSystem/Utilities/ArrayHelpers.cs 82.48% <100.00%> (+3.28%) ⬆️

... and 6 files with indirect coverage changes

ℹ️ Need help interpreting these results?

Copy link
Copy Markdown
Collaborator

@ekcoh ekcoh left a comment

Choose a reason for hiding this comment

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

2 issues called out by @u-pr that needs to be addressed (2 other bugs), also the PR is missing a CHANGELOG.md entry.

@K-Tone K-Tone changed the title Fix ISXB-1790: ArrayHelpers.Merge(IEqualityComparer) used wrong Equal… FIX: ArrayHelpers.Merge used the comparer incorrectly [ISXB-1790] Mar 27, 2026
@K-Tone
Copy link
Copy Markdown
Collaborator Author

K-Tone commented Mar 27, 2026

@u-pr can you check if all comments are resolved now?

@u-pr
Copy link
Copy Markdown
Contributor

u-pr bot commented Mar 27, 2026

Yes, all comments from previous reviews appear to be resolved in the latest changes:

  • HaveDuplicateReferences index fix: The loops in ArrayHelpers.cs (lines 119, 122) now correctly use the index and count parameters to define the search range.
  • HaveDuplicateReferences type constraint: The where TFirst : class constraint has been added to the method signature (line 117), preventing unnecessary boxing allocations.
  • Merge allocation & logic fix: The lambda expression in the Merge method has been replaced with a foreach loop (lines 554-563), and the call to comparer.Equals now correctly passes both arguments.
  • Regression Tests: New test cases (Utilities_HaveDuplicateReferences_DetectsDuplicatesInFullRange and Utilities_MergeWithComparer_UsesComparerToDeduplicate) have been added to ArrayHelperTests.cs to verify these fixes.

🤖 Helpful? 👍/👎

@K-Tone
Copy link
Copy Markdown
Collaborator Author

K-Tone commented Mar 27, 2026

CC @Pauliusd01 for viz - this is some internal thing fixed, not sure if you want to be a reviewer on this one.

Copy link
Copy Markdown
Collaborator

@ekcoh ekcoh left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the things found in review.

@K-Tone K-Tone merged commit aa0960d into develop Mar 27, 2026
125 checks passed
@K-Tone K-Tone deleted the fix/ISXB-1790-array-helpers-merge-comparer branch March 27, 2026 19:52
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.

2 participants