Skip to content

Commit 948f809

Browse files
committed
Handle _|_ - typed discriminants in alts correctly
Stop me, won't you, if you've heard this one before? Closes #794
1 parent 13f8b3f commit 948f809

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/comp/middle/trans_alt.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,18 @@ fn trans_alt(cx: &@block_ctxt, expr: &@ast::expr, arms: &ast::arm[],
425425
id: ast::node_id, output: &trans::out_method) -> result {
426426
let bodies = ~[];
427427
let match: match = ~[];
428+
let er = trans::trans_expr(cx, expr);
429+
if (ty::type_is_bot(bcx_tcx(cx), ty::expr_ty(bcx_tcx(cx), expr))) {
430+
// No need to generate code for alt,
431+
// since the disc diverges.
432+
if (!cx.build.is_terminated()) {
433+
ret rslt(cx, cx.build.Unreachable());
434+
}
435+
else {
436+
ret rslt(cx, C_nil());
437+
}
438+
}
439+
428440
for a: ast::arm in arms {
429441
let body = new_scope_block_ctxt(cx, "case_body");
430442
bodies += ~[body];
@@ -445,7 +457,6 @@ fn trans_alt(cx: &@block_ctxt, expr: &@ast::expr, arms: &ast::arm[],
445457
}
446458

447459
let exit_map = ~[];
448-
let er = trans::trans_expr(cx, expr);
449460
let t = trans::node_id_type(cx.fcx.lcx.ccx, expr.id);
450461
let v = trans::spill_if_immediate(er.bcx, er.val, t);
451462
compile_submatch(er.bcx, match, ~[v],

src/test/run-fail/alt-disc-bot.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// error-pattern:quux
2+
fn f() -> ! { fail "quux" }
3+
fn g() -> int { alt f() { true { 1 } false { 0 } }; }
4+
fn main() { g(); }

0 commit comments

Comments
 (0)