Skip to content

C#: Add ObjectInitMethod as enclosing callable for the instance initializers.#21490

Open
aschackmull wants to merge 2 commits intogithub:mainfrom
aschackmull:csharp/enclosing-obinit
Open

C#: Add ObjectInitMethod as enclosing callable for the instance initializers.#21490
aschackmull wants to merge 2 commits intogithub:mainfrom
aschackmull:csharp/enclosing-obinit

Conversation

@aschackmull
Copy link
Contributor

I believe this was an oversight in #20922.

@aschackmull aschackmull requested a review from a team as a code owner March 17, 2026 12:32
@aschackmull aschackmull added the no-change-note-required This PR does not need a change note label Mar 17, 2026
Copilot AI review requested due to automatic review settings March 17, 2026 12:32
@github-actions github-actions bot added the C# label Mar 17, 2026
Copy link
Contributor

Copilot AI left a 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 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 ObjectInitMethod via a new initializes(AssignExpr) predicate.
  • Update CFG scoping logic to use ObjectInitMethod.initializes directly.
  • 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.

@aschackmull aschackmull force-pushed the csharp/enclosing-obinit branch from c7c7a04 to 19faf8f Compare March 17, 2026 12:38
Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but some tests are failing and we also need a DCA run.

@aschackmull
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C# no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants