Revert "Revert "Handle conditionals on _|_ - typed values correctly""

This reverts commit ea81c03960.

Changed the case in trans_if where the conditional is _|_ - typed
but the block is terminated to return the result of the cond,
instead of nil.

This passes "make check" with optimization disabled as well as
enabled.
This commit is contained in:
Tim Chevalier 2011-08-03 13:05:46 -07:00
parent 513276e595
commit 001df3f0ca
2 changed files with 15 additions and 0 deletions

View File

@ -3592,6 +3592,18 @@ fn trans_if(cx: &@block_ctxt, cond: &@ast::expr, thn: &ast::blk,
els: &option::t[@ast::expr], id: ast::node_id,
output: &out_method) -> result {
let cond_res = trans_expr(cx, cond);
if (ty::type_is_bot(bcx_tcx(cx), ty::expr_ty(bcx_tcx(cx), cond))) {
// No need to generate code for comparison,
// since the cond diverges.
if (!cx.build.is_terminated()) {
ret rslt(cx, cx.build.Unreachable());
}
else {
ret cond_res;
}
}
let then_cx = new_scope_block_ctxt(cx, "then");
let then_res = trans_block(then_cx, thn, output);
let else_cx = new_scope_block_ctxt(cx, "else");

View File

@ -0,0 +1,3 @@
// error-pattern:quux
fn my_err(s: str) -> ! { log_err s; fail "quux"; }
fn main() { if my_err("bye") { } }