From a8a4d4ec056b68ac25a04ea020cdc674527a76df Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Wed, 10 Aug 2011 15:57:03 -0700 Subject: [PATCH] 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 --- src/comp/middle/trans.rs | 17 ++++++++++++++--- src/test/run-fail/bug-811.rs | 16 ++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/test/run-fail/bug-811.rs diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 6167bbcbe732..34a01bb2e813 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -995,7 +995,16 @@ fn get_tydesc(cx: &@block_ctxt, orig_t: &ty::t, escapes: bool, // Is the supplied type a type param? If so, return the passed-in tydesc. alt ty::type_param(bcx_tcx(cx), t) { - some(id) { ret rslt(cx, cx.fcx.lltydescs.(id)); } + some(id) { + if id < std::ivec::len(cx.fcx.lltydescs) { + ret rslt(cx, cx.fcx.lltydescs.(id)); + } + else { + bcx_tcx(cx).sess.span_bug(cx.sp, "Unbound typaram in get_tydesc: " + + "orig_t = " + ty_to_str(bcx_tcx(cx), orig_t) + + " ty_param = " + std::uint::str(id)); + } + } none. {/* fall through */ } } @@ -4517,7 +4526,9 @@ fn trans_arg_expr(cx: &@block_ctxt, arg: &ty::arg, // Collect arg for later if it happens to be one we've moving out. if arg.mode == ty::mo_move { if lv.is_mem { - to_zero += ~[{v: lv.res.val, t: arg.ty}]; + // Use actual ty, not declared ty -- anything else doesn't make sense + // if declared ty is a ty param + to_zero += ~[{v: lv.res.val, t: e_ty}]; } else { to_revoke += ~[lv.res.val]; } @@ -4668,7 +4679,7 @@ fn trans_call(cx: &@block_ctxt, f: &@ast::expr, /* log "calling: " + val_str(bcx_ccx(cx).tn, faddr); - for (ValueRef arg in llargs) { + for arg: ValueRef in llargs { log "arg: " + val_str(bcx_ccx(cx).tn, arg); } */ diff --git a/src/test/run-fail/bug-811.rs b/src/test/run-fail/bug-811.rs new file mode 100644 index 000000000000..2ecf7a7c29e3 --- /dev/null +++ b/src/test/run-fail/bug-811.rs @@ -0,0 +1,16 @@ +// error-pattern:quux +fn test00_start(ch: chan_t[int], message: int) { + send(ch, message); +} + +type task_id = int; +type port_id = int; + +type chan_t[~T] = { + task : task_id, + port : port_id +}; + +fn send[~T](ch : chan_t[T], data : -T) { fail; } + +fn main() { fail "quux"; }