Handle fail inside a for-each loop properly
This commit is contained in:
parent
ded9008e38
commit
a793b85fbd
4 changed files with 28 additions and 1 deletions
|
@ -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) {
|
||||
|
|
7
src/test/run-fail/fail-main.rs
Normal file
7
src/test/run-fail/fail-main.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
// xfail-stage0
|
||||
// error-pattern:moop
|
||||
use std;
|
||||
import std::uint;
|
||||
fn main() {
|
||||
fail "moop";
|
||||
}
|
9
src/test/run-fail/for-each-loop-fail.rs
Normal file
9
src/test/run-fail/for-each-loop-fail.rs
Normal 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";
|
||||
}
|
||||
}
|
7
src/test/run-pass/for-loop-fail.rs
Normal file
7
src/test/run-pass/for-loop-fail.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
// xfail-stage0
|
||||
fn main() {
|
||||
let vec[int] x = [];
|
||||
for (int i in x) {
|
||||
fail "moop";
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue