C#: Add types for pattern expressions. - #22681
Draft
michaelnebel wants to merge 3 commits into
Draft
michaelnebel wants to merge 3 commits into
michaelnebel wants to merge 3 commits into
Conversation
michaelnebel
force-pushed
the
csharp/patterntypes
branch
from
September 25, 2026 12:42
3f15531 to
0eb7911
Compare
Contributor
There was a problem hiding this comment.
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
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.
michaelnebel
force-pushed
the
csharp/patterntypes
branch
from
September 25, 2026 12:59
0eb7911 to
08cfad7
Compare
This branch has not been deployed
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.

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.