Skip to content

Commit fc6eb67

Browse files
committed
C#: Make positional pattern read step.
1 parent 6e44cf9 commit fc6eb67

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

‎csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,13 +563,19 @@ module LocalFlow {
563563
exists(IsExpr e |
564564
e1 = e.getExpr() and
565565
e2 = e.getPattern() and
566-
e2 instanceof TuplePatternExpr
566+
(
567+
e2 instanceof TuplePatternExpr or
568+
e2 instanceof RecursivePatternExpr
569+
)
567570
)
568571
or
569572
exists(Switch sw |
570573
e1 = sw.getExpr() and
571574
e2 = sw.getACase().getPattern() and
572-
e2 instanceof TuplePatternExpr
575+
(
576+
e2 instanceof TuplePatternExpr or
577+
e2 instanceof RecursivePatternExpr
578+
)
573579
)
574580
}
575581

@@ -2208,6 +2214,24 @@ predicate storeStep(Node node1, ContentSet c, Node node2) {
22082214
storeStepDelegateCall(node1, c, node2)
22092215
}
22102216

2217+
private predicate readStepPattern(Node node1, Content c, Node node2) {
2218+
exists(RecursivePatternExpr pattern, PatternExpr item, int i |
2219+
node1.asExpr() = pattern and
2220+
item = pattern.getPositionalPatterns().getPattern(i) and
2221+
c.(FieldContent).getField() =
2222+
pattern.getType().(TupleType).getElement(i).getUnboundDeclaration()
2223+
|
2224+
item = node2.asExpr().(RecursivePatternExpr)
2225+
or
2226+
item = node2.asExpr().(TuplePatternExpr)
2227+
or
2228+
exists(AssignableDefinitions::PatternDefinition lvd |
2229+
node2.(AssignableDefinitionNode).getDefinition() = lvd and
2230+
item = lvd.getDeclaration()
2231+
)
2232+
)
2233+
}
2234+
22112235
private predicate readContentStep(Node node1, Content c, Node node2) {
22122236
arrayRead(node1.asExpr(), node2.asExpr()) and
22132237
c instanceof ElementContent
@@ -2255,6 +2279,8 @@ private predicate readContentStep(Node node1, Content c, Node node2) {
22552279
)
22562280
)
22572281
or
2282+
readStepPattern(node1, c, node2)
2283+
or
22582284
VariableCapture::readStep(node1, c, node2)
22592285
}
22602286

0 commit comments

Comments
 (0)