Skip to content

Commit

Permalink
Handle conditionals on _|_ - typed values correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
catamorphism committed Aug 3, 2011
1 parent 7c34550 commit 13f8b3f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/comp/middle/trans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 rslt(cx, C_nil());
}
}

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");
Expand Down
3 changes: 3 additions & 0 deletions src/test/run-fail/if-cond-bot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// error-pattern:quux
fn my_err(s: str) -> ! { log_err s; fail "quux"; }
fn main() { if my_err("bye") { } }

0 comments on commit 13f8b3f

Please sign in to comment.