diff --git a/crates/nargo_cli/tests/test_data/closures_mut_ref/src/main.nr b/crates/nargo_cli/tests/test_data/closures_mut_ref/src/main.nr index e02cfb6880d..ae990e004fd 100644 --- a/crates/nargo_cli/tests/test_data/closures_mut_ref/src/main.nr +++ b/crates/nargo_cli/tests/test_data/closures_mut_ref/src/main.nr @@ -1,13 +1,14 @@ use dep::std; fn main(mut x: Field) { - + let one = 1; let add1 = |z| { - *z = *z + 1; + *z = *z + one; }; + let two = 2; let add2 = |z| { - *z = *z + 2; + *z = *z + two; }; add1(&mut x); diff --git a/crates/nargo_cli/tests/test_data/fibonacci_by_ref/src/main.nr b/crates/nargo_cli/tests/test_data/fibonacci_by_ref/src/main.nr index 763c5165c0f..d972e795822 100644 --- a/crates/nargo_cli/tests/test_data/fibonacci_by_ref/src/main.nr +++ b/crates/nargo_cli/tests/test_data/fibonacci_by_ref/src/main.nr @@ -5,11 +5,10 @@ fn fib_fn(a: Field, b: Field, res: &mut Field) { fn main(mut prev: Field, mut cur: Field) { let mut fib = prev + cur; - for i in 1..10 { + for _ in 1..10 { prev = cur; cur = fib; fib_fn(prev, cur, &mut fib); assert(prev + cur == fib); } - } diff --git a/crates/nargo_cli/tests/test_data/higher_order_fn_selector/src/main.nr b/crates/nargo_cli/tests/test_data/higher_order_fn_selector/src/main.nr index 3b8ec51ba00..4eabe059be0 100644 --- a/crates/nargo_cli/tests/test_data/higher_order_fn_selector/src/main.nr +++ b/crates/nargo_cli/tests/test_data/higher_order_fn_selector/src/main.nr @@ -1,3 +1,5 @@ +use dep::std; + fn f(x: &mut Field) -> Field { *x = *x - 1; 1 @@ -13,8 +15,6 @@ fn h(x: &mut Field) -> Field { 1 } -use dep::std; - fn selector(flag:&mut bool) -> fn(&mut Field) -> Field { //TODO: Can we have fn(&mut Field) -> () return type? let mut my_func = f; @@ -36,13 +36,13 @@ fn main() { let mut x: Field = 100; let returned_func = selector(&mut flag); - let status = returned_func(&mut x); + let _status = returned_func(&mut x); assert(x == 200); let mut y: Field = 100; let returned_func2 = selector(&mut flag); - let status2 = returned_func2(&mut y); + let _status2 = returned_func2(&mut y); assert(y == 300); diff --git a/crates/nargo_cli/tests/test_data/inner_outer_cl/src/main.nr b/crates/nargo_cli/tests/test_data/inner_outer_cl/src/main.nr index dcf97d709a9..ce847b56b93 100644 --- a/crates/nargo_cli/tests/test_data/inner_outer_cl/src/main.nr +++ b/crates/nargo_cli/tests/test_data/inner_outer_cl/src/main.nr @@ -1,10 +1,12 @@ fn main() { + let z1 = 0; + let z2 = 1; let cl_outer = |x| { let cl_inner = |y| { - x + y + x + y + z2 }; - cl_inner(1) + cl_inner(1) + z1 }; let result = cl_outer(1); - assert(result == 2); + assert(result == 3); } diff --git a/crates/nargo_cli/tests/test_data/ret_fn_ret_cl/src/main.nr b/crates/nargo_cli/tests/test_data/ret_fn_ret_cl/src/main.nr index 974c5321f64..d3a3346b541 100644 --- a/crates/nargo_cli/tests/test_data/ret_fn_ret_cl/src/main.nr +++ b/crates/nargo_cli/tests/test_data/ret_fn_ret_cl/src/main.nr @@ -1,29 +1,39 @@ use dep::std; fn f(x: Field) -> Field { - x + x + 1 } fn ret_fn() -> fn(Field) -> Field { - let y = 1; - let inner_closure = |z| -> Field{ - z + y - }; - std::println(inner_closure(1)); f } -fn ret_closure() -> fn(Field) -> Field { +// TODO: in the advanced implicitly generic function with closures branch +// which would support higher-order functions in a better way +// support returning closures: +// +// fn ret_closure() -> fn(Field) -> Field { +// let y = 1; +// let inner_closure = |z| -> Field{ +// z + y +// }; +// inner_closure +// } + +fn ret_lambda() -> fn(Field) -> Field { let cl = |z: Field| -> Field { - z + z + 1 }; cl } fn main(x : Field) { let result_fn = ret_fn(); - assert(result_fn(x) == x); // Works + assert(result_fn(x) == x + 1); + + // let result_closure = ret_closure(); + // assert(result_closure(x) == x + 1); - let result_cl = ret_closure(); - assert(result_cl(x) == x); + let result_lambda = ret_lambda(); + assert(result_lambda(x) == x + 1); }