Skip to content

C#: Data flow for property patterns. - #22757

Draft
michaelnebel wants to merge 4 commits into
github:mainfrom
michaelnebel:csharp/propertypatternflow
Draft

michaelnebel wants to merge 4 commits into
github:mainfrom
michaelnebel:csharp/propertypatternflow

Conversation

@michaelnebel

@michaelnebel michaelnebel commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

In this PR we added data flow support for property patterns. An example of a pattern pattern can be seen in the conditional of the if-statement below.

var i = 1;
var r = new C() { Prop = i };
if (r is C { Prop: int p })
{
    Sink(p); // $ has value flow 1
}

@michaelnebel
michaelnebel force-pushed the csharp/propertypatternflow branch from 74f8c46 to 62a81d4 Compare October 6, 2026 07:35
@github-actions github-actions Bot added the C# label Oct 6, 2026
@michaelnebel
michaelnebel force-pushed the csharp/propertypatternflow branch 2 times, most recently from b335b23 to 1638eb2 Compare October 6, 2026 11:31
@michaelnebel
michaelnebel requested a balanced review from Copilot October 6, 2026 12:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Pattern reads omit fields and can conflate hidden members with identical names.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds C# data-flow support for values extracted through property patterns.

Changes:

  • Adds property-pattern read steps.
  • Adds tests for nested, extended, generic, and tuple patterns.
  • Adds a change note.
File Description
Patterns.cs Adds property-pattern flow cases.
PatternFlow.expected Updates generated test expectations.
DataFlowPrivate.qll Implements pattern-member reads.
2026-10-06-property-pattern-flow.md Documents the analysis improvement.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll Outdated
@michaelnebel
michaelnebel force-pushed the csharp/propertypatternflow branch from 1638eb2 to 59612ef Compare October 6, 2026 12:37

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants