Skip to content

Commit bed1a4a

Browse files
committed
C#: Comment in the expected output in property pattern tests and add some extra tests.
1 parent 6f546d6 commit bed1a4a

2 files changed

Lines changed: 102 additions & 12 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,42 @@
11
models
22
edges
3+
| Patterns.cs:84:13:84:14 | access to local variable o2 : Object | Patterns.cs:85:51:85:52 | access to local variable o2 : Object | provenance | |
4+
| Patterns.cs:84:13:84:14 | access to local variable o2 : Object | Patterns.cs:85:51:85:52 | access to local variable o2 : Object | provenance | |
5+
| Patterns.cs:84:18:84:34 | call to method Source<Object> : Object | Patterns.cs:84:13:84:14 | access to local variable o2 : Object | provenance | |
6+
| Patterns.cs:84:18:84:34 | call to method Source<Object> : Object | Patterns.cs:84:13:84:14 | access to local variable o2 : Object | provenance | |
7+
| Patterns.cs:85:13:85:13 | access to local variable t : ValueTuple<Nested,Object> [field Item2] : Object | Patterns.cs:88:18:88:63 | { ... } : ValueTuple<Nested,Object> [field Item2] : Object | provenance | |
8+
| Patterns.cs:85:13:85:13 | access to local variable t : ValueTuple<Nested,Object> [field Item2] : Object | Patterns.cs:88:18:88:63 | { ... } : ValueTuple<Nested,Object> [field Item2] : Object | provenance | |
9+
| Patterns.cs:85:17:85:53 | (..., ...) : ValueTuple<Nested,Object> [field Item2] : Object | Patterns.cs:85:13:85:13 | access to local variable t : ValueTuple<Nested,Object> [field Item2] : Object | provenance | |
10+
| Patterns.cs:85:17:85:53 | (..., ...) : ValueTuple<Nested,Object> [field Item2] : Object | Patterns.cs:85:13:85:13 | access to local variable t : ValueTuple<Nested,Object> [field Item2] : Object | provenance | |
11+
| Patterns.cs:85:51:85:52 | access to local variable o2 : Object | Patterns.cs:85:17:85:53 | (..., ...) : ValueTuple<Nested,Object> [field Item2] : Object | provenance | |
12+
| Patterns.cs:85:51:85:52 | access to local variable o2 : Object | Patterns.cs:85:17:85:53 | (..., ...) : ValueTuple<Nested,Object> [field Item2] : Object | provenance | |
13+
| Patterns.cs:88:18:88:63 | { ... } : ValueTuple<Nested,Object> [field Item2] : Object | Patterns.cs:90:22:90:22 | access to local variable o | provenance | |
14+
| Patterns.cs:88:18:88:63 | { ... } : ValueTuple<Nested,Object> [field Item2] : Object | Patterns.cs:90:22:90:22 | access to local variable o | provenance | |
315
nodes
16+
| Patterns.cs:84:13:84:14 | access to local variable o2 : Object | semmle.label | access to local variable o2 : Object |
17+
| Patterns.cs:84:13:84:14 | access to local variable o2 : Object | semmle.label | access to local variable o2 : Object |
18+
| Patterns.cs:84:18:84:34 | call to method Source<Object> : Object | semmle.label | call to method Source<Object> : Object |
19+
| Patterns.cs:84:18:84:34 | call to method Source<Object> : Object | semmle.label | call to method Source<Object> : Object |
20+
| Patterns.cs:85:13:85:13 | access to local variable t : ValueTuple<Nested,Object> [field Item2] : Object | semmle.label | access to local variable t : ValueTuple<Nested,Object> [field Item2] : Object |
21+
| Patterns.cs:85:13:85:13 | access to local variable t : ValueTuple<Nested,Object> [field Item2] : Object | semmle.label | access to local variable t : ValueTuple<Nested,Object> [field Item2] : Object |
22+
| Patterns.cs:85:17:85:53 | (..., ...) : ValueTuple<Nested,Object> [field Item2] : Object | semmle.label | (..., ...) : ValueTuple<Nested,Object> [field Item2] : Object |
23+
| Patterns.cs:85:17:85:53 | (..., ...) : ValueTuple<Nested,Object> [field Item2] : Object | semmle.label | (..., ...) : ValueTuple<Nested,Object> [field Item2] : Object |
24+
| Patterns.cs:85:51:85:52 | access to local variable o2 : Object | semmle.label | access to local variable o2 : Object |
25+
| Patterns.cs:85:51:85:52 | access to local variable o2 : Object | semmle.label | access to local variable o2 : Object |
26+
| Patterns.cs:88:18:88:63 | { ... } : ValueTuple<Nested,Object> [field Item2] : Object | semmle.label | { ... } : ValueTuple<Nested,Object> [field Item2] : Object |
27+
| Patterns.cs:88:18:88:63 | { ... } : ValueTuple<Nested,Object> [field Item2] : Object | semmle.label | { ... } : ValueTuple<Nested,Object> [field Item2] : Object |
28+
| Patterns.cs:90:22:90:22 | access to local variable o | semmle.label | access to local variable o |
29+
| Patterns.cs:90:22:90:22 | access to local variable o | semmle.label | access to local variable o |
430
subpaths
531
testFailures
32+
| Patterns.cs:25:22:25:40 | // ... | Missing result: hasValueFlow=1 |
33+
| Patterns.cs:36:26:36:44 | // ... | Missing result: hasValueFlow=2 |
34+
| Patterns.cs:47:22:47:40 | // ... | Missing result: hasValueFlow=3 |
35+
| Patterns.cs:57:22:57:40 | // ... | Missing result: hasValueFlow=4 |
36+
| Patterns.cs:67:22:67:40 | // ... | Missing result: hasValueFlow=5 |
37+
| Patterns.cs:77:27:77:45 | // ... | Missing result: hasValueFlow=6 |
38+
| Patterns.cs:89:26:89:44 | // ... | Missing result: hasValueFlow=7 |
39+
| Patterns.cs:101:22:101:40 | // ... | Missing result: hasValueFlow=9 |
640
#select
41+
| Patterns.cs:90:22:90:22 | access to local variable o | Patterns.cs:84:18:84:34 | call to method Source<Object> : Object | Patterns.cs:90:22:90:22 | access to local variable o | $@ | Patterns.cs:84:18:84:34 | call to method Source<Object> : Object | call to method Source<Object> : Object |
42+
| Patterns.cs:90:22:90:22 | access to local variable o | Patterns.cs:84:18:84:34 | call to method Source<Object> : Object | Patterns.cs:90:22:90:22 | access to local variable o | $@ | Patterns.cs:84:18:84:34 | call to method Source<Object> : Object | call to method Source<Object> : Object |

‎csharp/ql/test/library-tests/dataflow/patterns/Patterns.cs‎

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,104 @@
11
using System;
22

3-
public record class RecordClass2(object Prop) { }
3+
public record class RecordClass(object Prop) { }
44

5-
public record class Nested(RecordClass2 Record) { }
5+
public record class Nested(RecordClass Record) { }
6+
7+
public class C1<T>
8+
{
9+
public T Prop { get; set; }
10+
}
11+
12+
public class C2
13+
{
14+
public string Field;
15+
}
616

717
public class RecordPatterns
818
{
919
private void M1()
1020
{
1121
var o = Source<object>(1);
12-
var r = new RecordClass2(o);
13-
if (r is RecordClass2 { Prop: object p })
22+
var r = new RecordClass(o);
23+
if (r is RecordClass { Prop: object p })
1424
{
15-
Sink(p); // $ MISSING: hasValueFlow=1
25+
Sink(p); // $ hasValueFlow=1
1626
}
1727
}
1828

1929
private void M2()
2030
{
2131
var o = Source<object>(2);
22-
var r = new RecordClass2(o);
32+
var r = new RecordClass(o);
2333
switch (r)
2434
{
25-
case RecordClass2 { Prop: object p }:
26-
Sink(p); // $ MISSING: hasValueFlow=2
35+
case RecordClass { Prop: object p }:
36+
Sink(p); // $ hasValueFlow=2
2737
break;
2838
}
2939
}
3040

3141
private void M3()
3242
{
3343
var o = Source<object>(3);
34-
var s = new Nested(new RecordClass2(o));
44+
var s = new Nested(new RecordClass(o));
3545
if (s is Nested { Record: { Prop: object p } })
3646
{
37-
Sink(p); // $ MISSING: hasValueFlow=3
47+
Sink(p); // $ hasValueFlow=3
3848
}
3949
}
4050

4151
private void M4()
4252
{
4353
var o = Source<object>(4);
44-
var s = new Nested(new RecordClass2(o));
54+
var s = new Nested(new RecordClass(o));
4555
if (s is Nested { Record.Prop: object p })
4656
{
47-
Sink(p); // $ MISSING: hasValueFlow=4
57+
Sink(p); // $ hasValueFlow=4
58+
}
59+
}
60+
61+
public void M5()
62+
{
63+
var o = Source<object>(5);
64+
var c = new C1<object> { Prop = o };
65+
if (c is C1<object> { Prop: object p })
66+
{
67+
Sink(p); // $ hasValueFlow=5
68+
}
69+
}
70+
71+
public void M6()
72+
{
73+
var o = Source<object>(6);
74+
var s = new Nested(new RecordClass(o));
75+
if (s is Nested { Record: RecordClass { Prop: var _ } r })
76+
{
77+
Sink(r.Prop); // $ hasValueFlow=6
78+
}
79+
}
80+
81+
public void M7()
82+
{
83+
var o1 = Source<object>(7);
84+
var o2 = Source<object>(8);
85+
var t = (new Nested(new RecordClass(o1)), o2);
86+
switch (t)
87+
{
88+
case (Nested { Record: { Prop: object p } }, var o):
89+
Sink(p); // $ hasValueFlow=7
90+
Sink(o); // $ hasValueFlow=8
91+
break;
92+
}
93+
}
94+
95+
public void M8()
96+
{
97+
var s = Source<string>(9);
98+
var c = new C2 { Field = s };
99+
if (c is C2 { Field: string p })
100+
{
101+
Sink(p); // $ hasValueFlow=9
48102
}
49103
}
50104

0 commit comments

Comments
 (0)