]> git.lizzy.rs Git - rust.git/commitdiff
Revert "Revert "Handle conditionals on _|_ - typed values correctly""
authorTim Chevalier <chevalier@alum.wellesley.edu>
Wed, 3 Aug 2011 20:05:46 +0000 (13:05 -0700)
committerTim Chevalier <chevalier@alum.wellesley.edu>
Wed, 3 Aug 2011 20:07:41 +0000 (13:07 -0700)
This reverts commit ea81c03960264bf590cd99ed2b662243e3db7a7c.

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.

src/comp/middle/trans.rs
src/test/run-fail/if-cond-bot.rs [new file with mode: 0644]

index 98ca83a6ff6d18fef643bd447a0e04b26e0bec0c..2d79053665a48f469fab36555823d59d5f17663b 100644 (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");
diff --git a/src/test/run-fail/if-cond-bot.rs b/src/test/run-fail/if-cond-bot.rs
new file mode 100644 (file)
index 0000000..32c6986
--- /dev/null
@@ -0,0 +1,3 @@
+// error-pattern:quux
+fn my_err(s: str) -> ! { log_err s; fail "quux"; }
+fn main() { if my_err("bye") { } }