aboutsummaryrefslogtreecommitdiff
path: root/src/comp/middle
diff options
context:
space:
mode:
authorBrian Anderson <[email protected]>2011-03-31 00:46:26 -0400
committerGraydon Hoare <[email protected]>2011-03-31 14:52:29 +0000
commitb0b72ab47228f3eada3077f1eaae15ae53006d1d (patch)
tree6057e0be60cf28db7ffad3d25828f60a20ed1477 /src/comp/middle
parentRemove redundant parser logic. (diff)
downloadrust-b0b72ab47228f3eada3077f1eaae15ae53006d1d.tar.xz
rust-b0b72ab47228f3eada3077f1eaae15ae53006d1d.zip
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.
Diffstat (limited to 'src/comp/middle')
-rw-r--r--src/comp/middle/trans.rs22
1 files 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)) {