Tests for type inferred lambda-blocks.

This commit is contained in:
Michael Sullivan 2011-08-15 15:34:47 -07:00
parent 9e084469af
commit 886c2ee93e
3 changed files with 15 additions and 6 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View 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];
}