diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2011-08-02 18:22:00 -0700 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2011-08-02 18:34:44 -0700 |
| commit | 13f8b3f2a67a4e3a7a26b0e238e1b6ce9e1f3573 (patch) | |
| tree | f9265543c49b6eb2e06ebdc88f17086f6a4d1882 | |
| parent | 7c34550931a457dd830173fc4a3c467a2ba2e784 (diff) | |
| download | rust-13f8b3f2a67a4e3a7a26b0e238e1b6ce9e1f3573.tar.gz rust-13f8b3f2a67a4e3a7a26b0e238e1b6ce9e1f3573.zip | |
Handle conditionals on _|_ - typed values correctly
Closes #776
| -rw-r--r-- | src/comp/middle/trans.rs | 12 | ||||
| -rw-r--r-- | src/test/run-fail/if-cond-bot.rs | 3 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 98ca83a6ff6..4d0d06eb5fb 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -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"); diff --git a/src/test/run-fail/if-cond-bot.rs b/src/test/run-fail/if-cond-bot.rs new file mode 100644 index 00000000000..32c698652e7 --- /dev/null +++ b/src/test/run-fail/if-cond-bot.rs @@ -0,0 +1,3 @@ +// error-pattern:quux +fn my_err(s: str) -> ! { log_err s; fail "quux"; } +fn main() { if my_err("bye") { } } |
