Skip to content

Commit

Permalink
C#: Add flow test cases for undetected value flow, when making variab…
Browse files Browse the repository at this point in the history
…le bindinds in pattern matching.
  • Loading branch information
michaelnebel committed Feb 2, 2022
1 parent e622e51 commit df0a1f3
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions csharp/ql/test/library-tests/dataflow/fields/K.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;

public record class RecordClass2(object Prop) { }

public record class Nested(RecordClass2 Record) { }

public class K
{
private void M1()
{
var o = Source<object>(1);
var r = new RecordClass2(o);
if (r is RecordClass2 { Prop: object p })
{
Sink(p); // $ MISSING: hasValueFlow=1
}
}

private void M2()
{
var o = Source<object>(2);
var r = new RecordClass2(o);
switch (r)
{
case RecordClass2 { Prop: object p }:
Sink(p); // $ MISSING: hasValueFlow=2
break;
}
}

private void M3()
{
var o = Source<object>(3);
var s = new Nested(new RecordClass2(o));
if (s is Nested { Record: { Prop: object p } })
{
Sink(p); // $ MISSING: hasValueFlow=3
}
}

private void M4()
{
var o = Source<object>(4);
var s = new Nested(new RecordClass2(o));
if (s is Nested { Record.Prop: object p })
{
Sink(p); // $ MISSING: hasValueFlow=4
}
}

public static void Sink(object o) { }

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

0 comments on commit df0a1f3

Please sign in to comment.