C#: Improve the query cs/gethashcode-is-not-defined.#19497
Merged
michaelnebel merged 5 commits intogithub:mainfrom May 16, 2025
Merged
C#: Improve the query cs/gethashcode-is-not-defined.#19497michaelnebel merged 5 commits intogithub:mainfrom
cs/gethashcode-is-not-defined.#19497michaelnebel merged 5 commits intogithub:mainfrom
Conversation
Contributor
Author
|
DCA looks good; We found a couple of extra results, but the query also performs slightly worse. |
Contributor
There was a problem hiding this comment.
Pull Request Overview
Enhance the cs/gethashcode-is-not-defined query to catch more hashing usages across both method calls and indexers, backed by new framework definitions and expanded tests.
- Extend the main QL predicate (
usesHashing) to include more methods and indexer accesses. - Add support for
IReadOnlyDictionaryandHashSetin the framework library. - Update test suite and change notes to reflect the broader detection.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| csharp/ql/src/Likely Bugs/HashedButNoHash.ql | Updated imports and predicates to cover additional scenarios, renamed and refactored predicates (usesHashing, dictionary, hashSet, hashStructure). |
| csharp/ql/lib/semmle/code/csharp/frameworks/system/collections/Generic.qll | Added IReadOnlyDictionary and HashSet class definitions. |
| csharp/ql/src/change-notes/2025-05-15-gethashcode-is-not-defined.md | Added change note documenting the precision improvements. |
| csharp/ql/test/query-tests/Likely Bugs/HashedButNoHash/HashedButNoHash.qlref | Adjusted test metadata to use query: and postprocess: directives. |
| csharp/ql/test/query-tests/Likely Bugs/HashedButNoHash/HashedButNoHash.expected | Expanded expected alerts to cover the new hashing calls. |
| csharp/ql/test/query-tests/Likely Bugs/HashedButNoHash/HashedButNoHash.cs | Added more hashing-related calls (Contains, Remove, TryAdd, TryGetValue) to the test case. |
Comments suppressed due to low confidence (3)
csharp/ql/src/Likely Bugs/HashedButNoHash.ql:29
- The Javadoc comment refers to parameter
cbut the predicate declares parametert; consider updating the comment to match the actual parameter name for clarity.
/** Holds if `c` is a hashset type. */
csharp/ql/src/Likely Bugs/HashedButNoHash.ql:14
- The import path uses an uppercase 'Collections' segment, which may be inconsistent with the lowercase directory naming used elsewhere; please verify the correct casing for the module path.
import semmle.code.csharp.frameworks.system.Collections
csharp/ql/src/change-notes/2025-05-15-gethashcode-is-not-defined.md:1
- [nitpick] The frontmatter defines only
category; to maintain consistency with other change notes, consider adding atitlefield or confirming this matches the existing style conventions.
---
hvitved
approved these changes
May 16, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Even though there is a general compiler warning CS0659 for all types overriding
Equalsbut notGetHashCode- this query only targets expressions of types, where it is more likely to have an impact thatGetHashCode()is not overridden.