Skip to content

Commit 13b8d57

Browse files
committed
C#: Add collection flow test cases for collection expressions.
1 parent 168f5b5 commit 13b8d57

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

csharp/ql/test/library-tests/dataflow/collections/CollectionFlow.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,4 +414,38 @@ public void InlineArraySetterNoFlow(A other)
414414
array[0] = other;
415415
Sink(array[0]); // no flow
416416
}
417+
418+
public void CollectionExpressionNoFlow(A a)
419+
{
420+
A[] array = [a];
421+
Sink(array[0]); // no flow
422+
}
423+
424+
public void CollectionExpressionElementFlow()
425+
{
426+
var a = new A();
427+
A[] array = [a];
428+
Sink(array[0]); // flow
429+
}
430+
431+
public void CollectionExpressionElementFlowList()
432+
{
433+
var a = new A();
434+
List<A> l = [a];
435+
Sink(l[0]); // flow
436+
}
437+
438+
public void CollectionExpressionSpreadElementNoFlow(A[] other)
439+
{
440+
A[] array = [.. other];
441+
Sink(array[0]); // no flow
442+
}
443+
444+
public void CollectionExpressionSpreadElementFlow()
445+
{
446+
var a = new A();
447+
A[] temp = [a];
448+
A[] array = [.. temp];
449+
Sink(array[0]); // flow
450+
}
417451
}

csharp/ql/test/library-tests/dataflow/collections/CollectionFlow.expected

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@ edges
233233
| CollectionFlow.cs:407:9:407:13 | [post] access to local variable array : MyInlineArray [element] : A | CollectionFlow.cs:408:14:408:18 | access to local variable array : MyInlineArray [element] : A |
234234
| CollectionFlow.cs:407:20:407:20 | access to local variable a : A | CollectionFlow.cs:407:9:407:13 | [post] access to local variable array : MyInlineArray [element] : A |
235235
| CollectionFlow.cs:408:14:408:18 | access to local variable array : MyInlineArray [element] : A | CollectionFlow.cs:408:14:408:21 | access to array element |
236+
| CollectionFlow.cs:426:17:426:23 | object creation of type A : A | CollectionFlow.cs:427:22:427:22 | access to local variable a : A |
237+
| CollectionFlow.cs:427:21:427:23 | [...] : A[] [element] : A | CollectionFlow.cs:428:14:428:18 | access to local variable array : A[] [element] : A |
238+
| CollectionFlow.cs:427:22:427:22 | access to local variable a : A | CollectionFlow.cs:427:21:427:23 | [...] : A[] [element] : A |
239+
| CollectionFlow.cs:428:14:428:18 | access to local variable array : A[] [element] : A | CollectionFlow.cs:428:14:428:21 | access to array element |
240+
| CollectionFlow.cs:433:17:433:23 | object creation of type A : A | CollectionFlow.cs:434:22:434:22 | access to local variable a : A |
241+
| CollectionFlow.cs:434:21:434:23 | [...] : List<A> [element] : A | CollectionFlow.cs:435:14:435:14 | access to local variable l : List<A> [element] : A |
242+
| CollectionFlow.cs:434:22:434:22 | access to local variable a : A | CollectionFlow.cs:434:21:434:23 | [...] : List<A> [element] : A |
243+
| CollectionFlow.cs:435:14:435:14 | access to local variable l : List<A> [element] : A | CollectionFlow.cs:435:14:435:17 | access to indexer |
244+
| CollectionFlow.cs:446:17:446:23 | object creation of type A : A | CollectionFlow.cs:447:21:447:21 | access to local variable a : A |
245+
| CollectionFlow.cs:447:20:447:22 | [...] : A[] [element] : A | CollectionFlow.cs:449:14:449:18 | access to local variable array : A[] [element] : A |
246+
| CollectionFlow.cs:447:21:447:21 | access to local variable a : A | CollectionFlow.cs:447:20:447:22 | [...] : A[] [element] : A |
247+
| CollectionFlow.cs:449:14:449:18 | access to local variable array : A[] [element] : A | CollectionFlow.cs:449:14:449:21 | access to array element |
236248
nodes
237249
| CollectionFlow.cs:13:40:13:41 | ts : A[] [element] : A | semmle.label | ts : A[] [element] : A |
238250
| CollectionFlow.cs:13:40:13:41 | ts : null [element] : A | semmle.label | ts : null [element] : A |
@@ -468,6 +480,21 @@ nodes
468480
| CollectionFlow.cs:407:20:407:20 | access to local variable a : A | semmle.label | access to local variable a : A |
469481
| CollectionFlow.cs:408:14:408:18 | access to local variable array : MyInlineArray [element] : A | semmle.label | access to local variable array : MyInlineArray [element] : A |
470482
| CollectionFlow.cs:408:14:408:21 | access to array element | semmle.label | access to array element |
483+
| CollectionFlow.cs:426:17:426:23 | object creation of type A : A | semmle.label | object creation of type A : A |
484+
| CollectionFlow.cs:427:21:427:23 | [...] : A[] [element] : A | semmle.label | [...] : A[] [element] : A |
485+
| CollectionFlow.cs:427:22:427:22 | access to local variable a : A | semmle.label | access to local variable a : A |
486+
| CollectionFlow.cs:428:14:428:18 | access to local variable array : A[] [element] : A | semmle.label | access to local variable array : A[] [element] : A |
487+
| CollectionFlow.cs:428:14:428:21 | access to array element | semmle.label | access to array element |
488+
| CollectionFlow.cs:433:17:433:23 | object creation of type A : A | semmle.label | object creation of type A : A |
489+
| CollectionFlow.cs:434:21:434:23 | [...] : List<A> [element] : A | semmle.label | [...] : List<A> [element] : A |
490+
| CollectionFlow.cs:434:22:434:22 | access to local variable a : A | semmle.label | access to local variable a : A |
491+
| CollectionFlow.cs:435:14:435:14 | access to local variable l : List<A> [element] : A | semmle.label | access to local variable l : List<A> [element] : A |
492+
| CollectionFlow.cs:435:14:435:17 | access to indexer | semmle.label | access to indexer |
493+
| CollectionFlow.cs:446:17:446:23 | object creation of type A : A | semmle.label | object creation of type A : A |
494+
| CollectionFlow.cs:447:20:447:22 | [...] : A[] [element] : A | semmle.label | [...] : A[] [element] : A |
495+
| CollectionFlow.cs:447:21:447:21 | access to local variable a : A | semmle.label | access to local variable a : A |
496+
| CollectionFlow.cs:449:14:449:18 | access to local variable array : A[] [element] : A | semmle.label | access to local variable array : A[] [element] : A |
497+
| CollectionFlow.cs:449:14:449:21 | access to array element | semmle.label | access to array element |
471498
subpaths
472499
| CollectionFlow.cs:43:20:43:22 | access to local variable as : null [element] : A | CollectionFlow.cs:21:34:21:35 | ts : null [element] : A | CollectionFlow.cs:21:41:21:45 | access to array element : A | CollectionFlow.cs:43:14:43:23 | call to method First<A> |
473500
| CollectionFlow.cs:61:20:61:23 | access to field As : A[] [element] : A | CollectionFlow.cs:21:34:21:35 | ts : A[] [element] : A | CollectionFlow.cs:21:41:21:45 | access to array element : A | CollectionFlow.cs:61:14:61:24 | call to method First<A> |
@@ -549,3 +576,6 @@ subpaths
549576
| CollectionFlow.cs:374:26:374:32 | object creation of type A : A | CollectionFlow.cs:374:26:374:32 | object creation of type A : A | CollectionFlow.cs:35:63:35:69 | access to array element | $@ | CollectionFlow.cs:35:63:35:69 | access to array element | access to array element |
550577
| CollectionFlow.cs:375:30:375:36 | object creation of type A : A | CollectionFlow.cs:375:30:375:36 | object creation of type A : A | CollectionFlow.cs:35:63:35:69 | access to array element | $@ | CollectionFlow.cs:35:63:35:69 | access to array element | access to array element |
551578
| CollectionFlow.cs:405:17:405:23 | object creation of type A : A | CollectionFlow.cs:405:17:405:23 | object creation of type A : A | CollectionFlow.cs:408:14:408:21 | access to array element | $@ | CollectionFlow.cs:408:14:408:21 | access to array element | access to array element |
579+
| CollectionFlow.cs:426:17:426:23 | object creation of type A : A | CollectionFlow.cs:426:17:426:23 | object creation of type A : A | CollectionFlow.cs:428:14:428:21 | access to array element | $@ | CollectionFlow.cs:428:14:428:21 | access to array element | access to array element |
580+
| CollectionFlow.cs:433:17:433:23 | object creation of type A : A | CollectionFlow.cs:433:17:433:23 | object creation of type A : A | CollectionFlow.cs:435:14:435:17 | access to indexer | $@ | CollectionFlow.cs:435:14:435:17 | access to indexer | access to indexer |
581+
| CollectionFlow.cs:446:17:446:23 | object creation of type A : A | CollectionFlow.cs:446:17:446:23 | object creation of type A : A | CollectionFlow.cs:449:14:449:21 | access to array element | $@ | CollectionFlow.cs:449:14:449:21 | access to array element | access to array element |

0 commit comments

Comments
 (0)