Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#: Add flow test cases for undetected value flow, when making variable bindings in pattern matching. #7809

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
failures
edges
nodes
subpaths
#select
11 changes: 11 additions & 0 deletions csharp/ql/test/library-tests/dataflow/patterns/PatternFlow.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @kind path-problem
*/

import csharp
import DataFlow::PathGraph
import TestUtilities.InlineFlowTest

from DataFlow::PathNode source, DataFlow::PathNode sink, DefaultValueFlowConf conf
where conf.hasFlowPath(source, sink)
select sink, source, sink, "$@", source, source.toString()
54 changes: 54 additions & 0 deletions csharp/ql/test/library-tests/dataflow/patterns/Patterns.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;
}