Skip to content

Commit 63f9428

Browse files
committed
C#: Add some positional pattern data flow tests.
1 parent 11b8755 commit 63f9428

3 files changed

Lines changed: 169 additions & 14 deletions

File tree

‎csharp/ql/test/library-tests/dataflow/tuples/DataFlowStep.expected‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,40 @@
226226
| Tuples.cs:133:24:133:29 | (..., ...) | Tuples.cs:133:9:133:20 | (..., ...) |
227227
| Tuples.cs:133:25:133:25 | 1 | Tuples.cs:133:9:133:29 | ... = ... |
228228
| Tuples.cs:133:28:133:28 | access to local variable o | Tuples.cs:133:18:133:19 | access to local variable y4 |
229-
| Tuples.cs:144:18:144:31 | this | Tuples.cs:144:18:144:31 | this access |
229+
| Tuples.cs:139:13:139:14 | access to local variable o1 | Tuples.cs:139:13:139:35 | SSA def(o1) |
230+
| Tuples.cs:139:13:139:35 | SSA def(o1) | Tuples.cs:141:18:141:19 | access to local variable o1 |
231+
| Tuples.cs:139:18:139:35 | call to method Source<String> | Tuples.cs:139:13:139:14 | access to local variable o1 |
232+
| Tuples.cs:139:33:139:34 | 10 | Tuples.cs:139:33:139:34 | (...) ... |
233+
| Tuples.cs:140:13:140:14 | access to local variable o2 | Tuples.cs:140:13:140:35 | SSA def(o2) |
234+
| Tuples.cs:140:13:140:35 | SSA def(o2) | Tuples.cs:141:26:141:27 | access to local variable o2 |
235+
| Tuples.cs:140:18:140:35 | call to method Source<String> | Tuples.cs:140:13:140:14 | access to local variable o2 |
236+
| Tuples.cs:140:33:140:34 | 11 | Tuples.cs:140:33:140:34 | (...) ... |
237+
| Tuples.cs:141:13:141:13 | access to local variable x | Tuples.cs:141:13:141:32 | SSA def(x) |
238+
| Tuples.cs:141:13:141:32 | SSA def(x) | Tuples.cs:142:17:142:17 | access to local variable x |
239+
| Tuples.cs:141:17:141:32 | (..., ...) | Tuples.cs:141:13:141:13 | access to local variable x |
240+
| Tuples.cs:144:19:144:24 | SSA def(a1) | Tuples.cs:145:22:145:23 | access to local variable a1 |
241+
| Tuples.cs:144:19:144:24 | String a1 | Tuples.cs:144:19:144:24 | SSA def(a1) |
242+
| Tuples.cs:144:28:144:33 | Int32 b1 | Tuples.cs:144:28:144:33 | SSA def(b1) |
243+
| Tuples.cs:144:28:144:33 | SSA def(b1) | Tuples.cs:147:22:147:23 | access to local variable b1 |
244+
| Tuples.cs:144:36:144:41 | SSA def(c1) | Tuples.cs:146:22:146:23 | access to local variable c1 |
245+
| Tuples.cs:144:36:144:41 | String c1 | Tuples.cs:144:36:144:41 | SSA def(c1) |
246+
| Tuples.cs:147:22:147:23 | access to local variable b1 | Tuples.cs:147:22:147:23 | (...) ... |
247+
| Tuples.cs:151:13:151:14 | access to local variable o3 | Tuples.cs:151:13:151:35 | SSA def(o3) |
248+
| Tuples.cs:151:13:151:35 | SSA def(o3) | Tuples.cs:153:18:153:19 | access to local variable o3 |
249+
| Tuples.cs:151:18:151:35 | call to method Source<String> | Tuples.cs:151:13:151:14 | access to local variable o3 |
250+
| Tuples.cs:151:33:151:34 | 12 | Tuples.cs:151:33:151:34 | (...) ... |
251+
| Tuples.cs:152:13:152:14 | access to local variable o4 | Tuples.cs:152:13:152:35 | SSA def(o4) |
252+
| Tuples.cs:152:13:152:35 | SSA def(o4) | Tuples.cs:153:26:153:27 | access to local variable o4 |
253+
| Tuples.cs:152:18:152:35 | call to method Source<String> | Tuples.cs:152:13:152:14 | access to local variable o4 |
254+
| Tuples.cs:152:33:152:34 | 13 | Tuples.cs:152:33:152:34 | (...) ... |
255+
| Tuples.cs:153:13:153:13 | access to local variable y | Tuples.cs:153:13:153:32 | SSA def(y) |
256+
| Tuples.cs:153:13:153:32 | SSA def(y) | Tuples.cs:154:13:154:13 | access to local variable y |
257+
| Tuples.cs:153:17:153:32 | (..., ...) | Tuples.cs:153:13:153:13 | access to local variable y |
258+
| Tuples.cs:154:19:154:24 | SSA def(a2) | Tuples.cs:156:18:156:19 | access to local variable a2 |
259+
| Tuples.cs:154:19:154:24 | String a2 | Tuples.cs:154:19:154:24 | SSA def(a2) |
260+
| Tuples.cs:154:32:154:33 | Int32 b2 | Tuples.cs:154:32:154:33 | SSA def(b2) |
261+
| Tuples.cs:154:32:154:33 | SSA def(b2) | Tuples.cs:158:18:158:19 | access to local variable b2 |
262+
| Tuples.cs:154:36:154:37 | SSA def(c2) | Tuples.cs:157:18:157:19 | access to local variable c2 |
263+
| Tuples.cs:154:36:154:37 | String c2 | Tuples.cs:154:36:154:37 | SSA def(c2) |
264+
| Tuples.cs:158:18:158:19 | access to local variable b2 | Tuples.cs:158:18:158:19 | (...) ... |
265+
| Tuples.cs:169:18:169:31 | this | Tuples.cs:169:18:169:31 | this access |

‎csharp/ql/test/library-tests/dataflow/tuples/PrintAst.expected‎

Lines changed: 107 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -504,20 +504,114 @@ Tuples.cs:
504504
# 134| 12: [ExprStmt] ...;
505505
# 134| 0: [MethodCall] call to method Sink
506506
# 134| 0: [LocalVariableAccess] access to local variable y4
507-
# 137| 13: [Method] Sink
507+
# 137| 13: [Method] M7
508508
# 137| -1: [TypeMention] Void
509+
# 138| 4: [BlockStmt] {...}
510+
# 139| 0: [LocalVariableDeclStmt] ... ...;
511+
# 139| 0: [LocalVariableDeclAndInitExpr] String o1 = ...
512+
# 139| -1: [TypeMention] string
513+
# 139| 0: [LocalVariableAccess] access to local variable o1
514+
# 139| 1: [MethodCall] call to method Source<String>
515+
# 139| 0: [CastExpr] (...) ...
516+
# 139| 1: [IntLiteral] 10
517+
# 140| 1: [LocalVariableDeclStmt] ... ...;
518+
# 140| 0: [LocalVariableDeclAndInitExpr] String o2 = ...
519+
# 140| -1: [TypeMention] string
520+
# 140| 0: [LocalVariableAccess] access to local variable o2
521+
# 140| 1: [MethodCall] call to method Source<String>
522+
# 140| 0: [CastExpr] (...) ...
523+
# 140| 1: [IntLiteral] 11
524+
# 141| 2: [LocalVariableDeclStmt] ... ...;
525+
# 141| 0: [LocalVariableDeclAndInitExpr] (String,(Int32,String),Int32) x = ...
526+
# 141| -1: [TypeMention] (string, (int, string), int)
527+
# 141| 0: [LocalVariableAccess] access to local variable x
528+
# 141| 1: [TupleExpr] (..., ...)
529+
# 141| 0: [LocalVariableAccess] access to local variable o1
530+
# 141| 1: [TupleExpr] (..., ...)
531+
# 141| 0: [IntLiteral] 2
532+
# 141| 1: [LocalVariableAccess] access to local variable o2
533+
# 141| 2: [IntLiteral] 3
534+
# 142| 3: [SwitchStmt] switch (...) {...}
535+
# 142| 0: [LocalVariableAccess] access to local variable x
536+
# 144| 0: [CaseStmt] case ...:
537+
# 144| 0: [RecursivePatternExpr] { ... }
538+
# 144| 2: [PositionalPatternExpr] ( ... )
539+
# 144| 0: [VariablePatternExpr] String a1
540+
# 144| 1: [RecursivePatternExpr] { ... }
541+
# 144| 2: [PositionalPatternExpr] ( ... )
542+
# 144| 0: [VariablePatternExpr] Int32 b1
543+
# 144| 1: [VariablePatternExpr] String c1
544+
# 144| 2: [DiscardPatternExpr] _
545+
# 145| 1: [ExprStmt] ...;
546+
# 145| 0: [MethodCall] call to method Sink
547+
# 145| 0: [LocalVariableAccess] access to local variable a1
548+
# 146| 2: [ExprStmt] ...;
549+
# 146| 0: [MethodCall] call to method Sink
550+
# 146| 0: [LocalVariableAccess] access to local variable c1
551+
# 147| 3: [ExprStmt] ...;
552+
# 147| 0: [MethodCall] call to method Sink
553+
# 147| 0: [CastExpr] (...) ...
554+
# 147| 1: [LocalVariableAccess] access to local variable b1
555+
# 148| 4: [BreakStmt] break;
556+
# 151| 4: [LocalVariableDeclStmt] ... ...;
557+
# 151| 0: [LocalVariableDeclAndInitExpr] String o3 = ...
558+
# 151| -1: [TypeMention] string
559+
# 151| 0: [LocalVariableAccess] access to local variable o3
560+
# 151| 1: [MethodCall] call to method Source<String>
561+
# 151| 0: [CastExpr] (...) ...
562+
# 151| 1: [IntLiteral] 12
563+
# 152| 5: [LocalVariableDeclStmt] ... ...;
564+
# 152| 0: [LocalVariableDeclAndInitExpr] String o4 = ...
565+
# 152| -1: [TypeMention] string
566+
# 152| 0: [LocalVariableAccess] access to local variable o4
567+
# 152| 1: [MethodCall] call to method Source<String>
568+
# 152| 0: [CastExpr] (...) ...
569+
# 152| 1: [IntLiteral] 13
570+
# 153| 6: [LocalVariableDeclStmt] ... ...;
571+
# 153| 0: [LocalVariableDeclAndInitExpr] (String,(Int32,String),Int32) y = ...
572+
# 153| -1: [TypeMention] (string, (int, string), int)
573+
# 153| 0: [LocalVariableAccess] access to local variable y
574+
# 153| 1: [TupleExpr] (..., ...)
575+
# 153| 0: [LocalVariableAccess] access to local variable o3
576+
# 153| 1: [TupleExpr] (..., ...)
577+
# 153| 0: [IntLiteral] 2
578+
# 153| 1: [LocalVariableAccess] access to local variable o4
579+
# 153| 2: [IntLiteral] 3
580+
# 154| 7: [IfStmt] if (...) ...
581+
# 154| 0: [IsExpr] ... is ...
582+
# 154| 0: [LocalVariableAccess] access to local variable y
583+
# 154| 1: [RecursivePatternExpr] { ... }
584+
# 154| 2: [PositionalPatternExpr] ( ... )
585+
# 154| 0: [VariablePatternExpr] String a2
586+
# 154| 1: [TuplePatternExpr] (..., ...)
587+
# 154| 0: [VariablePatternExpr] Int32 b2
588+
# 154| 1: [VariablePatternExpr] String c2
589+
# 154| 2: [DiscardPatternExpr] _
590+
# 155| 1: [BlockStmt] {...}
591+
# 156| 0: [ExprStmt] ...;
592+
# 156| 0: [MethodCall] call to method Sink
593+
# 156| 0: [LocalVariableAccess] access to local variable a2
594+
# 157| 1: [ExprStmt] ...;
595+
# 157| 0: [MethodCall] call to method Sink
596+
# 157| 0: [LocalVariableAccess] access to local variable c2
597+
# 158| 2: [ExprStmt] ...;
598+
# 158| 0: [MethodCall] call to method Sink
599+
# 158| 0: [CastExpr] (...) ...
600+
# 158| 1: [LocalVariableAccess] access to local variable b2
601+
# 162| 14: [Method] Sink
602+
# 162| -1: [TypeMention] Void
509603
#-----| 2: (Parameters)
510-
# 137| 0: [Parameter] o
511-
# 137| -1: [TypeMention] object
512-
# 137| 4: [BlockStmt] {...}
513-
# 139| 16: [Method] Source`1
514-
# 139| -1: [TypeMention] T
604+
# 162| 0: [Parameter] o
605+
# 162| -1: [TypeMention] object
606+
# 162| 4: [BlockStmt] {...}
607+
# 164| 17: [Method] Source`1
608+
# 164| -1: [TypeMention] T
515609
#-----| 1: (Type parameters)
516-
# 139| 0: [TypeParameter] T
610+
# 164| 0: [TypeParameter] T
517611
#-----| 2: (Parameters)
518-
# 139| 0: [Parameter] source
519-
# 139| -1: [TypeMention] object
520-
# 139| 4: [ThrowExpr] throw ...
521-
# 139| 0: [NullLiteral] null
522-
# 142| [NamespaceDeclaration] namespace ... { ... }
523-
# 144| 1: [Class] IsExternalInit
612+
# 164| 0: [Parameter] source
613+
# 164| -1: [TypeMention] object
614+
# 164| 4: [ThrowExpr] throw ...
615+
# 164| 0: [NullLiteral] null
616+
# 167| [NamespaceDeclaration] namespace ... { ... }
617+
# 169| 1: [Class] IsExternalInit

‎csharp/ql/test/library-tests/dataflow/tuples/Tuples.cs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,31 @@ static void M6()
134134
Sink(y4); // $ hasValueFlow=9
135135
}
136136

137+
static void M7()
138+
{
139+
var o1 = Source<string>(10);
140+
var o2 = Source<string>(11);
141+
var x = (o1, (2, o2), 3);
142+
switch (x)
143+
{
144+
case (var a1, (var b1, var c1), _):
145+
Sink(a1); // $ MISSING: hasValueFlow=10
146+
Sink(c1); // $ MISSING: hasValueFlow=11
147+
Sink(b1);
148+
break;
149+
}
150+
151+
var o3 = Source<string>(12);
152+
var o4 = Source<string>(13);
153+
var y = (o3, (2, o4), 3);
154+
if (y is (var a2, var (b2, c2), _))
155+
{
156+
Sink(a2); // $ MISSING: hasValueFlow=12
157+
Sink(c2); // $ MISSING: hasValueFlow=13
158+
Sink(b2);
159+
}
160+
}
161+
137162
public static void Sink(object o) { }
138163

139164
static T Source<T>(object source) => throw null;

0 commit comments

Comments
 (0)