From b0b72ab47228f3eada3077f1eaae15ae53006d1d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 31 Mar 2011 00:46:26 -0400 Subject: Restore scope block contexts to the translation of expr_block. I removed this previously but that was wrong because it caused block expressions to not create a new scope. --- src/comp/middle/trans.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 2471d85e..a32faddf 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -3063,7 +3063,18 @@ fn trans_if(@block_ctxt cx, @ast.expr cond, auto expr_llty; alt (els) { case (some[@ast.expr](?elexpr)) { - else_res = trans_expr(else_cx, elexpr); + alt (elexpr.node) { + case (ast.expr_if(_, _, _, _)) { + else_res = trans_expr(else_cx, elexpr); + } + case (ast.expr_block(?blk, _)) { + // Calling trans_block directly instead of trans_expr + // because trans_expr will create another scope block + // context for the block, but we've already got the + // 'else' context + else_res = trans_block(else_cx, blk); + } + } // If we have an else expression, then the entire // if expression can have a non-nil type. @@ -4617,7 +4628,14 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result { } case (ast.expr_block(?blk, _)) { - ret trans_block(cx, blk); + auto sub_cx = new_scope_block_ctxt(cx, "block-expr body"); + auto next_cx = new_sub_block_ctxt(cx, "next"); + auto sub = trans_block(sub_cx, blk); + + cx.build.Br(sub_cx.llbb); + sub.bcx.build.Br(next_cx.llbb); + + ret res(next_cx, sub.val); } case (ast.expr_assign(?dst, ?src, ?ann)) { -- cgit v1.2.3