rustc: Translate else if blocks the same as other blocks. Closes #388

This commit is contained in:
Brian Anderson 2011-05-19 20:26:42 -04:00
parent 879a952a37
commit b6d2fe4d74
3 changed files with 16 additions and 11 deletions

View file

@ -3670,15 +3670,18 @@ fn trans_if(&@block_ctxt cx, &@ast::expr cond,
alt (els) {
case (some[@ast::expr](?elexpr)) {
alt (elexpr.node) {
case (ast::expr_if(?cond, ?thn, ?els, _)) {
else_res = trans_if(else_cx, cond, thn, els);
// The if expression may need to use the else context to
// drop the refcount of its result so we need to run the
// cleanups
auto bcx = else_res.bcx;
bcx = trans_block_cleanups(bcx,
find_scope_cx(bcx));
else_res = res(bcx, else_res.val);
case (ast::expr_if(_, _, _, ?ann)) {
// Synthesize a block here to act as the else block
// containing an if expression. Needed in order for the
// else scope to behave like a normal block scope. A tad
// ugly.
let ast::block_ elseif_blk_
= rec(stmts = [],
expr = some[@ast::expr](elexpr),
a = ann);
auto elseif_blk = rec(node = elseif_blk_,
span = elexpr.span);
else_res = trans_block(else_cx, elseif_blk);
}
case (ast::expr_block(?blk, _)) {
// Calling trans_block directly instead of trans_expr

View file

@ -1,5 +1,7 @@
// xfail-stage0
// Regression test for issue #388
fn main() {
auto x = {{[10]}};
}

View file

@ -1,6 +1,6 @@
// xfail-stage0
// xfail-stage1
// xfail-stage2
// Regression test for issue #388
fn main() {
auto x = if (false) {