C#: Add ObjectInitMethod as enclosing callable for the instance initializers.#21490
Conversation
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
left a comment
There was a problem hiding this comment.
LGTM, but some tests are failing and we also need a DCA run.
The test changes look correct to me, so I've pushed a commit accepting them. I'll start dca now. |
|
Dca shows a few additional alerts - they look plausibly reasonable to me. And there's no impact on performance. |
I believe this was an oversight in #20922.