forked from noir-lang/noir
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: capture some variables in some tests, fix warnings, add a TODO
add a TODO about returning closures
- Loading branch information
1 parent
c0b2567
commit 45a3a52
Showing
5 changed files
with
35 additions
and
23 deletions.
There are no files selected for viewing
7 changes: 4 additions & 3 deletions
7
crates/nargo_cli/tests/test_data/closures_mut_ref/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
32 changes: 21 additions & 11 deletions
32
crates/nargo_cli/tests/test_data/ret_fn_ret_cl/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |