Skip to content

Commit

Permalink
rustc: Translate else if blocks the same as other blocks. Closes #388
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed May 20, 2011
1 parent 879a952 commit b6d2fe4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
21 changes: 12 additions & 9 deletions src/comp/middle/trans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/expr-block-ref.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// xfail-stage0

// Regression test for issue #388

fn main() {
auto x = {{[10]}};
}
4 changes: 2 additions & 2 deletions src/test/run-pass/expr-elseif-ref2.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// xfail-stage0
// xfail-stage1
// xfail-stage2

// Regression test for issue #388

fn main() {
auto x = if (false) {
Expand Down

0 comments on commit b6d2fe4

Please sign in to comment.