Skip to content

Commit fbfd855

Browse files
committed
Return a better result from blocks. Closes issue #377
Blocks return in a copy of the result of their ending expression, not the direct result of the ending expression, as that may be a local variable which gets zeroed by drop_slot.
1 parent 4539b3f commit fbfd855

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/comp/middle/trans.rs

+3
Original file line numberDiff line numberDiff line change
@@ -6252,6 +6252,9 @@ fn trans_block(&@block_ctxt cx, &ast::block b) -> result {
62526252
auto cleanup = bind drop_hoisted_ty(_, res_alloca.val,
62536253
r_ty);
62546254
find_outer_scope_cx(bcx).cleanups += [clean(cleanup)];
6255+
6256+
r = res(bcx, load_if_immediate(bcx,
6257+
res_alloca.val, r_ty));
62556258
}
62566259
}
62576260
}

src/test/run-pass/expr-block-slot.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// xfail-stage0
2+
3+
// Regression test for issue #377
4+
5+
fn main() {
6+
auto a = {
7+
auto b = tup(3);
8+
b
9+
};
10+
11+
assert a._0 == 3;
12+
13+
auto c = {
14+
auto d = rec(v=3);
15+
d
16+
};
17+
18+
assert c.v == 3;
19+
}

0 commit comments

Comments
 (0)