diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 82ba8654bb3..433a8012873 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -3049,6 +3049,9 @@ fn trans_if(@block_ctxt cx, @ast.expr cond, // FIXME: Handle dynamic type sizes auto expr_ty = ty.expr_ty(elexpr); expr_llty = type_of(else_res.bcx.fcx.ccx, expr_ty); + if (ty.type_is_structural(expr_ty)) { + expr_llty = T_ptr(expr_llty); + } } case (_) { else_res = res(else_cx, C_nil()); diff --git a/src/test/run-pass/expr-if-struct.rs b/src/test/run-pass/expr-if-struct.rs new file mode 100644 index 00000000000..df20a3bae60 --- /dev/null +++ b/src/test/run-pass/expr-if-struct.rs @@ -0,0 +1,24 @@ +// xfail-boot +// -*- rust -*- + +// Tests for if as expressions returning structural types + +fn test_rec() { + auto res = if (true) { rec(i = 100) } else { rec(i = 101) }; + check (res == rec(i = 100)); +} + +fn test_tag() { + tag mood { + happy; + sad; + } + + auto res = if (true) { happy } else { sad }; + check (res == happy); +} + +fn main() { + test_rec(); + test_tag(); +} \ No newline at end of file