Skip to content

Commit c9e702d

Browse files
committed
Rest: Add tests for higher-order functions
1 parent 8d01bbc commit c9e702d

File tree

4 files changed

+258
-165
lines changed

4 files changed

+258
-165
lines changed

rust/ql/test/library-tests/dataflow/models/main.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,34 @@ fn test_set_tuple_element() {
175175
sink(t.1); // $ hasValueFlow=11
176176
}
177177

178+
// has a flow model
179+
pub fn apply<F>(n: i64, f: F) -> i64 where F : FnOnce(i64) -> i64 {
180+
0
181+
}
182+
183+
fn test_apply_flow_in() {
184+
let s = source(83);
185+
let f = |n| {
186+
sink(n); // $ hasValueFlow=83
187+
n + 3
188+
};
189+
apply(s, f);
190+
}
191+
192+
fn test_apply_flow_out() {
193+
let s = source(86);
194+
let f = |n| if n != 0 { n } else { s };
195+
let t = apply(34, f);
196+
sink(t); // $ MISSING: hasValueFlow=86
197+
}
198+
199+
fn test_apply_flow_through() {
200+
let s = source(33);
201+
let f = |n| if n != 0 { n } else { 0 };
202+
let t = apply(s, f);
203+
sink(t); // $ hasValueFlow=33
204+
}
205+
178206
impl MyFieldEnum {
179207
// has a source model
180208
fn source(&self, i: i64) -> MyFieldEnum {

0 commit comments

Comments
 (0)