C#: Improve cs/dereference-* queries and add to the Code Quality suite.#19589
Merged
michaelnebel merged 8 commits intogithub:mainfrom Jun 11, 2025
Merged
C#: Improve cs/dereference-* queries and add to the Code Quality suite.#19589michaelnebel merged 8 commits intogithub:mainfrom
cs/dereference-* queries and add to the Code Quality suite.#19589michaelnebel merged 8 commits intogithub:mainfrom
Conversation
c1e05e6 to
09f9849
Compare
…ine expectations.
…referenced-value-is-always-null.
…e-may-be-null to the Code Quality suites.
f1f2d6f to
bc4ff59
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the null-dereference queries by treating nullable extension-method receivers as potentially safe, removes strict type checks on Debug.Assert, and folds the new queries into the Code Quality suite with inline-expectation tests.
- Broaden
cs/dereferenced-value-is-always-null/cs/dereferenced-value-may-be-nullto ignore null dereferences inside library extension methods on nullable receivers. - Simplify Debug.Assert matching by dropping parameter-type checks.
- Add both queries to the Code Quality query suite and convert tests to use inline expectations.
Reviewed Changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| csharp/ql/src/change-notes/2025-06-03-dereferece-extension-method.md | Adds change note for extension-method deref behavior (typo in name) |
| csharp/ql/lib/semmle/code/csharp/frameworks/system/Diagnostics.qll | Loosen Assert matcher to any Assert overload without param check |
| csharp/ql/lib/semmle/code/csharp/dataflow/Nullness.qll | Update Dereference predicate to treat nullable extension receivers safely |
| csharp/ql/integration-tests/posix/query-suite/csharp-code-quality.qls.expected | Include the new queries in the Code Quality suite |
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.
In this PR we do the following for
cs/dereferenced-value-is-always-nullandcs/dereferenced-value-may-be-null.thisparameter is a nullable type, we now assume that the null may happen in the extension method itself (this is at least common for the usage of testing frameworks, which reports a high amount of false positives related to the use of such extension methods).DCA looks good.