C#: Add ObjectInitMethod as enclosing callable for the instance initializers.#21490
Open
aschackmull wants to merge 2 commits intogithub:mainfrom
Open
C#: Add ObjectInitMethod as enclosing callable for the instance initializers.#21490aschackmull wants to merge 2 commits intogithub:mainfrom
aschackmull wants to merge 2 commits intogithub:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses an oversight from #20922 by ensuring instance member initializer assignments are associated with the extractor-synthesized ObjectInitMethod as their enclosing callable (improving enclosing-callable / CFG scoping behavior around instance initializers).
Changes:
- Move/centralize the “object initializer initializes assignment” relation onto
ObjectInitMethodvia a newinitializes(AssignExpr)predicate. - Update CFG scoping logic to use
ObjectInitMethod.initializesdirectly. - Update enclosing-callable computation to treat initializer assignment expressions as enclosed by the corresponding
ObjectInitMethod.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraphImpl.qll | Switches initializer ordering/scoping logic to use ObjectInitMethod.initializes instead of a local helper predicate. |
| csharp/ql/lib/semmle/code/csharp/ExprOrStmtParent.qll | Extends enclosing-callable relation to include initializer assignment expressions for ObjectInitMethod. |
| csharp/ql/lib/semmle/code/csharp/Callable.qll | Introduces InitializedInstanceMember and adds ObjectInitMethod.initializes(AssignExpr) to expose the relationship as a reusable API. |
You can also share your feedback on Copilot code review. Take the survey.
c7c7a04 to
19faf8f
Compare
hvitved
requested changes
Mar 17, 2026
Contributor
hvitved
left a comment
There was a problem hiding this comment.
LGTM, but some tests are failing and we also need a DCA run.
Contributor
Author
The test changes look correct to me, so I've pushed a commit accepting them. I'll start dca now. |
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.
I believe this was an oversight in #20922.