diff --git a/csharp/ql/test/library-tests/dataflow/fields/K.cs b/csharp/ql/test/library-tests/dataflow/fields/K.cs new file mode 100644 index 0000000000000..37728dd403958 --- /dev/null +++ b/csharp/ql/test/library-tests/dataflow/fields/K.cs @@ -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(1); + var r = new RecordClass2(o); + if (r is RecordClass2 { Prop: object p }) + { + Sink(p); // $ MISSING: hasValueFlow=1 + } + } + + private void M2() + { + var o = Source(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(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(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(object source) => throw null; +}