Skip to content

C#: Add types for pattern expressions. - #22681

Draft
michaelnebel wants to merge 3 commits into
github:mainfrom
michaelnebel:csharp/patterntypes
Draft

michaelnebel wants to merge 3 commits into
github:mainfrom
michaelnebel:csharp/patterntypes

Conversation

@michaelnebel

@michaelnebel michaelnebel commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

This adds types to most of the pattern expressions. The only exclusions are property pattern- and positional pattern expressions, but they are mostly used as a part of a recursive pattern - which is then either a property- or positional pattern as a child (maybe patterns could have been modelled differently - but that is out of scope for this PR). The "type" is then added to the recursive pattern itself.

@github-actions github-actions Bot added the C# label Sep 25, 2026

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

The converted-type helper records the unconverted type’s nullability annotation.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds extracted types for C# pattern expressions across supported language versions.

Changes:

  • Adds converted-type extraction for six pattern kinds.
  • Introduces a reusable converted-type helper.
  • Adds C# 8, 9, and 11 test coverage.
File Description
csharp/​extractor/​Semmle.Extraction.CSharp/​CodeAnalysisExtensions/​SymbolExtensions.cs Adds converted-type lookup.
csharp/​extractor/​Semmle.Extraction.CSharp/​Entities/​Expressions/​Patterns/​BinaryPattern.cs Types binary patterns.
csharp/​extractor/​Semmle.Extraction.CSharp/​Entities/​Expressions/​Patterns/​ListPattern.cs Types list patterns.
csharp/​extractor/​Semmle.Extraction.CSharp/​Entities/​Expressions/​Patterns/​RecursivePattern.cs Types recursive patterns.
csharp/​extractor/​Semmle.Extraction.CSharp/​Entities/​Expressions/​Patterns/​RelationalPattern.cs Types relational patterns.
csharp/​extractor/​Semmle.Extraction.CSharp/​Entities/​Expressions/​Patterns/​SlicePattern.cs Types slice patterns.
csharp/​extractor/​Semmle.Extraction.CSharp/​Entities/​Expressions/​Patterns/​UnaryPattern.cs Types unary patterns.
csharp/​ql/​test/​library-tests/​csharp8/​patterns.ql Queries extracted pattern types.
csharp/​ql/​test/​library-tests/​csharp8/​patterns.expected Updates C# 8 expected results.
csharp/​ql/​test/​library-tests/​csharp9/​patternExprTypes.ql Adds C# 9 type query.
csharp/​ql/​test/​library-tests/​csharp9/​patternExprTypes.expected Adds C# 9 expected results.
csharp/​ql/​test/​library-tests/​csharp11/​patternExprTypes.ql Adds C# 11 type query.
csharp/​ql/​test/​library-tests/​csharp11/​patternExprTypes.expected Adds C# 11 expected results.

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

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants