-
Notifications
You must be signed in to change notification settings - Fork 1.7k
C#: Improve cs/dereference-*
queries and add to the Code Quality suite.
#19589
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
base: main
Are you sure you want to change the base?
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
There was a problem hiding this 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 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-null
to 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 |
In this PR we do the following for
cs/dereferenced-value-is-always-null
andcs/dereferenced-value-may-be-null
.this
parameter 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.