aboutsummaryrefslogtreecommitdiff
path: root/src/comp
diff options
context:
space:
mode:
authorBrian Anderson <[email protected]>2011-03-27 16:29:21 -0400
committerGraydon Hoare <[email protected]>2011-03-28 21:14:03 -0700
commita5a319fa047b04b525066d560115ad93a18e4a4f (patch)
treeaf19f3a3b4416049149e05020df2df849a8e0383 /src/comp
parentAdd expr_spawn, spawn parsing, folding, typechecking, ty_task (diff)
downloadrust-a5a319fa047b04b525066d560115ad93a18e4a4f.tar.xz
rust-a5a319fa047b04b525066d560115ad93a18e4a4f.zip
Teach rustc to use the result of if expressions
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/trans.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 28f79dbb..82ba8654 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -3037,21 +3037,30 @@ fn trans_if(@block_ctxt cx, @ast.expr cond,
auto then_res = trans_block(then_cx, thn);
auto else_cx = new_scope_block_ctxt(cx, "else");
- auto else_res = res(else_cx, C_nil());
+ auto else_res;
+ auto expr_llty;
alt (els) {
case (some[@ast.expr](?elexpr)) {
else_res = trans_expr(else_cx, elexpr);
+
+ // If we have an else expression, then the entire
+ // if expression can have a non-nil type.
+ // FIXME: Handle dynamic type sizes
+ auto expr_ty = ty.expr_ty(elexpr);
+ expr_llty = type_of(else_res.bcx.fcx.ccx, expr_ty);
+ }
+ case (_) {
+ else_res = res(else_cx, C_nil());
+ expr_llty = T_nil();
}
- case (_) { /* fall through */ }
}
cond_res.bcx.build.CondBr(cond_res.val,
then_cx.llbb,
else_cx.llbb);
- // FIXME: use inferred type when available.
- ret join_results(cx, T_nil(),
+ ret join_results(cx, expr_llty,
vec(then_res, else_res));
}