Repository navigation
Conversation
Co-authored-by: Copilot App <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Stale test baselines are expected to fail with the rebuilt extractor, and new pattern accesses are misclassified as variable uses, producing self-referential jump-to-definition links.
2 open issues
What changed in this PR
Adds defining accesses for C# pattern variables so the extractor and QL libraries expose them consistently as write targets.
Changes:
- Reuse defining-access extraction for typed,
var, recursive, and tuple patterns. - Associate pattern definitions with write-only target accesses and clarify API documentation.
- Add regression coverage, update affected test expectations, and document the change.
| File | Description |
|---|---|
csharp/ql/test/library-tests/dataflow/patterns/PatternFlow.expected |
Adds pattern-definition steps to expected data-flow paths. |
csharp/ql/test/library-tests/csharp9/PrintAst.expected |
Includes defining accesses in C# 9 pattern ASTs. |
csharp/ql/test/library-tests/csharp8/switchstmtctrlflow.expected |
Updates switch-statement control-flow expectations. |
csharp/ql/test/library-tests/csharp8/switchexprcontrolflow.expected |
Updates switch-expression control-flow expectations. |
csharp/ql/test/library-tests/csharp8/PrintAst.expected |
Includes defining accesses in C# 8 pattern ASTs. |
csharp/ql/test/library-tests/csharp8/patterns.ql |
Checks access targets and write-only classification. |
csharp/ql/test/library-tests/csharp8/patterns.expected |
Records expected defining-access regression results. |
csharp/ql/test/library-tests/csharp8/ispatternflow.expected |
Updates is-pattern control-flow expectations. |
csharp/ql/test/library-tests/csharp7/PrintAst.expected |
Includes defining accesses in C# 7 pattern ASTs. |
csharp/ql/test/library-tests/csharp7/LocalTaintFlow.expected |
Uses defining accesses in expected taint-flow steps. |
csharp/ql/test/library-tests/csharp7/IsFlow.expected |
Includes defining accesses in pattern control flow. |
csharp/ql/test/library-tests/csharp11/PrintAst.expected |
Includes defining accesses within list patterns. |
csharp/ql/test/library-tests/controlflow/graph/NodeGraph.expected |
Adds access nodes and their control-flow edges. |
csharp/ql/test/library-tests/controlflow/graph/EntryElement.expected |
Updates pattern entry elements. |
csharp/ql/test/library-tests/controlflow/graph/EnclosingCallable.expected |
Associates new nodes with their enclosing callables. |
csharp/ql/test/library-tests/controlflow/graph/Dominance.expected |
Updates dominance and post-dominance expectations. |
csharp/ql/test/library-tests/controlflow/graph/Condition.expected |
Updates conditional-flow endpoints. |
csharp/ql/test/library-tests/controlflow/graph/BasicBlock.expected |
Updates basic-block node counts. |
csharp/ql/test/library-tests/assignables/AssignableDefinition.expected |
Records target accesses for pattern definitions. |
csharp/ql/test/library-tests/assignables/AssignableAccess.expected |
Classifies pattern defining accesses as writes. |
csharp/ql/lib/semmle/code/csharp/exprs/Expr.qll |
Clarifies the getAccess() docstring. |
csharp/ql/lib/semmle/code/csharp/Assignable.qll |
Maps pattern definitions to target accesses and updates documentation. |
csharp/ql/lib/change-notes/2026-11-20-pattern-defining-access.md |
Documents pattern defining-access support. |
csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/VariableDeclaration.cs |
Shares defining-access creation and enables it for patterns. |
csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Patterns/RecursivePattern.cs |
Enables defining-access extraction for recursive patterns. |
csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Patterns/Pattern.cs |
Enables defining-access extraction for typed and var patterns. |
Review effort: Max
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
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.


The C# extractor recorded local variables declared in patterns such as
o is MyStruct ms1, but omitted their defining access. As a result,LocalVariableDeclExpr.getAccess()returned no result for those declarations.Reuse the defining-access extraction from ordinary initialized declarations for typed,
var, recursive, and tuple patterns. The QL library treats the access as the pattern definition's write target, not as a read. Ordinary declarations and discards are unchanged.The regression test verifies that each pattern access targets the declared variable and is classified as a write. Rebuilt the extractor and ran 124 related C# tests, including the affected AST, control-flow, and data-flow tests.