Skip to content

Commit ade119f

Browse files
committed
C#: Add flow test cases for undetected value flow, when making variable bindinds in pattern matching.
1 parent e9b496b commit ade119f

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
failures
2+
edges
3+
nodes
4+
subpaths
5+
#select
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @kind path-problem
3+
*/
4+
5+
import csharp
6+
import DataFlow::PathGraph
7+
import TestUtilities.InlineFlowTest
8+
9+
from DataFlow::PathNode source, DataFlow::PathNode sink, DefaultValueFlowConf conf
10+
where conf.hasFlowPath(source, sink)
11+
select sink, source, sink, "$@", source, source.toString()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
3+
public record class RecordClass2(object Prop) { }
4+
5+
public record class Nested(RecordClass2 Record) { }
6+
7+
public class K
8+
{
9+
private void M1()
10+
{
11+
var o = Source<object>(1);
12+
var r = new RecordClass2(o);
13+
if (r is RecordClass2 { Prop: object p })
14+
{
15+
Sink(p); // $ MISSING: hasValueFlow=1
16+
}
17+
}
18+
19+
private void M2()
20+
{
21+
var o = Source<object>(2);
22+
var r = new RecordClass2(o);
23+
switch (r)
24+
{
25+
case RecordClass2 { Prop: object p }:
26+
Sink(p); // $ MISSING: hasValueFlow=2
27+
break;
28+
}
29+
}
30+
31+
private void M3()
32+
{
33+
var o = Source<object>(3);
34+
var s = new Nested(new RecordClass2(o));
35+
if (s is Nested { Record: { Prop: object p } })
36+
{
37+
Sink(p); // $ MISSING: hasValueFlow=3
38+
}
39+
}
40+
41+
private void M4()
42+
{
43+
var o = Source<object>(4);
44+
var s = new Nested(new RecordClass2(o));
45+
if (s is Nested { Record.Prop: object p })
46+
{
47+
Sink(p); // $ MISSING: hasValueFlow=4
48+
}
49+
}
50+
51+
public static void Sink(object o) { }
52+
53+
static T Source<T>(object source) => throw null;
54+
}

0 commit comments

Comments
 (0)