Handle fail inside a for-each loop properly

This commit is contained in:
Tim Chevalier 2011-07-05 15:59:04 -07:00
parent ded9008e38
commit a793b85fbd
4 changed files with 28 additions and 1 deletions

View file

@ -4564,7 +4564,11 @@ fn trans_for_each(&@block_ctxt cx, &@ast::local local, &@ast::expr seq,
auto lltop = bcx.llbb;
auto r = trans_block(bcx, body, return);
finish_fn(fcx, lltop);
r.bcx.build.RetVoid();
if (!r.bcx.build.is_terminated()) {
// if terminated is true, no need for the ret-fail
r.bcx.build.RetVoid();
}
// Step 3: Call iter passing [lliterbody, llenv], plus other args.
alt (seq.node) {

View file

@ -0,0 +1,7 @@
// xfail-stage0
// error-pattern:moop
use std;
import std::uint;
fn main() {
fail "moop";
}

View file

@ -0,0 +1,9 @@
// xfail-stage0
// error-pattern:moop
use std;
import std::uint;
fn main() {
for each (uint i in uint::range(0u, 10u)) {
fail "moop";
}
}

View file

@ -0,0 +1,7 @@
// xfail-stage0
fn main() {
let vec[int] x = [];
for (int i in x) {
fail "moop";
}
}