Skip to content

C#: Increase precision of cs/useless-gethashcode-call. #19010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

michaelnebel
Copy link
Contributor

@michaelnebel michaelnebel commented Mar 13, 2025

As this table indicates, only byte, sbyte, short, ushort and int can use the identity function for GetHashCode (and they indeed do so) as the return type of GetHashCode is int.
In this PR we update the cs/useless-gethashcode-call to exclude calls to GetHashCode on uint, long and ulong and convert the tests to inline tests.

@github-actions github-actions bot added the C# label Mar 13, 2025
@michaelnebel michaelnebel marked this pull request as ready for review March 13, 2025 13:02
@Copilot Copilot AI review requested due to automatic review settings March 13, 2025 13:02
@michaelnebel michaelnebel requested a review from a team as a code owner March 13, 2025 13:02
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR increases the precision of the cs/useless-gethashcode-call query by excluding calls to GetHashCode on uint, long, and ulong from being flagged. It also converts the tests to inline tests and updates the change note accordingly.

  • Updated change note file to document the refined behavior.
  • Modified the test file to flag only calls on int, short, ushort, byte, and sbyte.

Reviewed Changes

Copilot reviewed 2 out of 5 changed files in this pull request and generated no comments.

File Description
csharp/ql/src/change-notes/2025-03-13-useless-gethashcode-call.md Adds a change note specifying the increased precision.
csharp/ql/test/query-tests/Useless Code/IntGetHashCode/IntGetHashCode.cs Converts tests to inline tests with alerts for specific types.
Files not reviewed (3)
  • csharp/ql/src/Useless code/IntGetHashCode.ql: Language not supported
  • csharp/ql/test/query-tests/Useless Code/IntGetHashCode/IntGetHashCode.expected: Language not supported
  • csharp/ql/test/query-tests/Useless Code/IntGetHashCode/IntGetHashCode.qlref: Language not supported

Tip: Copilot only keeps its highest confidence comments to reduce noise and keep you focused. Learn more

@michaelnebel
Copy link
Contributor Author

DCA looks good.

@michaelnebel michaelnebel merged commit 563ffb8 into github:main Mar 14, 2025
22 checks passed
@michaelnebel michaelnebel deleted the csharp/useless-gethashcode-call branch March 14, 2025 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants