Tests for type inferred lambda-blocks.
This commit is contained in:
parent
9e084469af
commit
886c2ee93e
@ -4,11 +4,11 @@ fn main() {
|
||||
let v = ~[1, 2, 3, 4, 5, 6, 7];
|
||||
let odds = 0;
|
||||
iter_vec(v,
|
||||
block (i: &int) {
|
||||
{|&i|
|
||||
log_err i;
|
||||
if i % 2 == 1 { odds += 1; }
|
||||
log_err odds;
|
||||
});
|
||||
log_err odds;
|
||||
assert (odds == 4);
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,9 @@ fn main() {
|
||||
let v = ~[1, 2, 3, 4, 5];
|
||||
let sum = 0;
|
||||
iter_vec(v,
|
||||
block (i: &int) {
|
||||
iter_vec(v,
|
||||
block (j: &int) { log_err i * j; sum += i * j; });
|
||||
{|&i|
|
||||
iter_vec(v, {|&j| log_err i * j; sum += i * j; });
|
||||
});
|
||||
log_err sum;
|
||||
assert (sum == 225);
|
||||
}
|
||||
}
|
||||
|
10
src/test/run-pass/block-vec-map2.rs
Normal file
10
src/test/run-pass/block-vec-map2.rs
Normal file
@ -0,0 +1,10 @@
|
||||
use std;
|
||||
import std::ivec;
|
||||
|
||||
fn main() {
|
||||
let v = std::ivec::map2({|&i, &b| if b { -i } else { i }},
|
||||
~[1, 2, 3, 4, 5],
|
||||
~[true, false, false, true, true]);
|
||||
log_err v;
|
||||
assert v == ~[-1, 2, 3, -4, -5];
|
||||
}
|
Loading…
Reference in New Issue
Block a user