C#: Allow virtual member access in nameof expressions in cs/virtual-call-in-constructor.#22205
Open
michaelnebel wants to merge 5 commits into
Open
C#: Allow virtual member access in nameof expressions in cs/virtual-call-in-constructor.#22205michaelnebel wants to merge 5 commits into
nameof expressions in cs/virtual-call-in-constructor.#22205michaelnebel wants to merge 5 commits into
Conversation
c7e0d75 to
b52ea33
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refines the C# query cs/virtual-call-in-constructor to avoid reporting virtual-member references that occur inside nameof(...) expressions, eliminating a known false positive (notably in dotnet/efcore) while keeping the query’s intent focused on actual virtual calls/accesses that can dispatch at runtime.
Changes:
- Update the query to exclude virtual member accesses that are part of a
nameofargument expression. - Extend the query test case to include
nameofusage over virtual members (including a chained member access case). - Add a change note and refresh the
.expectedtest output accordingly.
Show a summary per file
| File | Description |
|---|---|
| csharp/ql/src/Bad Practices/VirtualCallInConstructorOrDestructor.ql | Excludes virtual member access within nameof(...) from being reported by the query. |
| csharp/ql/test/query-tests/Bad Practices/VirtualCallInConstructorOrDestructor/VirtualCallInConstructorOrDestructor.cs | Adds nameof examples that should not produce alerts, including a chained access case. |
| csharp/ql/test/query-tests/Bad Practices/VirtualCallInConstructorOrDestructor/VirtualCallInConstructorOrDestructor.expected | Updates expected results to match the refined query behavior and shifted test line numbers. |
| csharp/ql/src/change-notes/2026-07-16-virtual-call-in-constructor.md | Documents the behavioral improvement as a minor analysis change. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Low
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.
DCA looks good.
dotnet/efcore.