Skip to content

Commit a8a4d4e

Browse files
committed
Use actual type, not declared type, when zeroing move arguments
trans was failing with a bounds check error because the caller was using the declared type (an out-of-scope ty param) and not the actual type in a list of argument types to zero. Closes #811
1 parent 6b756c4 commit a8a4d4e

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/comp/middle/trans.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,16 @@ fn get_tydesc(cx: &@block_ctxt, orig_t: &ty::t, escapes: bool,
995995

996996
// Is the supplied type a type param? If so, return the passed-in tydesc.
997997
alt ty::type_param(bcx_tcx(cx), t) {
998-
some(id) { ret rslt(cx, cx.fcx.lltydescs.(id)); }
998+
some(id) {
999+
if id < std::ivec::len(cx.fcx.lltydescs) {
1000+
ret rslt(cx, cx.fcx.lltydescs.(id));
1001+
}
1002+
else {
1003+
bcx_tcx(cx).sess.span_bug(cx.sp, "Unbound typaram in get_tydesc: "
1004+
+ "orig_t = " + ty_to_str(bcx_tcx(cx), orig_t)
1005+
+ " ty_param = " + std::uint::str(id));
1006+
}
1007+
}
9991008
none. {/* fall through */ }
10001009
}
10011010

@@ -4517,7 +4526,9 @@ fn trans_arg_expr(cx: &@block_ctxt, arg: &ty::arg,
45174526
// Collect arg for later if it happens to be one we've moving out.
45184527
if arg.mode == ty::mo_move {
45194528
if lv.is_mem {
4520-
to_zero += ~[{v: lv.res.val, t: arg.ty}];
4529+
// Use actual ty, not declared ty -- anything else doesn't make sense
4530+
// if declared ty is a ty param
4531+
to_zero += ~[{v: lv.res.val, t: e_ty}];
45214532
} else {
45224533
to_revoke += ~[lv.res.val];
45234534
}
@@ -4668,7 +4679,7 @@ fn trans_call(cx: &@block_ctxt, f: &@ast::expr,
46684679
/*
46694680
log "calling: " + val_str(bcx_ccx(cx).tn, faddr);
46704681
4671-
for (ValueRef arg in llargs) {
4682+
for arg: ValueRef in llargs {
46724683
log "arg: " + val_str(bcx_ccx(cx).tn, arg);
46734684
}
46744685
*/

src/test/run-fail/bug-811.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// error-pattern:quux
2+
fn test00_start(ch: chan_t[int], message: int) {
3+
send(ch, message);
4+
}
5+
6+
type task_id = int;
7+
type port_id = int;
8+
9+
type chan_t[~T] = {
10+
task : task_id,
11+
port : port_id
12+
};
13+
14+
fn send[~T](ch : chan_t[T], data : -T) { fail; }
15+
16+
fn main() { fail "quux"; }

0 commit comments

Comments
 (0)