Fix broken determination of external method type param count

Closes #2185
This commit is contained in:
Marijn Haverbeke 2012-04-23 09:25:14 +02:00
parent 512927573e
commit dfdca5d538
3 changed files with 15 additions and 4 deletions

View File

@ -2341,7 +2341,7 @@ fn trans_callee(bcx: block, e: @ast::expr) -> lval_maybe_callee {
let _icx = bcx.insn_ctxt("trans_callee");
alt e.node {
ast::expr_path(path) { ret trans_path(bcx, e.id); }
ast::expr_field(base, ident, _) {
ast::expr_field(base, _, _) {
// Lval means this is a record field, so not a method
if !expr_is_lval(bcx, e) {
alt bcx.ccx().maps.method_map.find(e.id) {

View File

@ -95,13 +95,15 @@ fn method_with_name(ccx: @crate_ctxt, impl_id: ast::def_id,
}
}
fn method_ty_param_count(ccx: @crate_ctxt, m_id: ast::def_id) -> uint {
fn method_ty_param_count(ccx: @crate_ctxt, m_id: ast::def_id,
i_id: ast::def_id) -> uint {
if m_id.crate == ast::local_crate {
alt check ccx.tcx.items.get(m_id.node) {
ast_map::node_method(m, _, _) { vec::len(m.tps) }
}
} else {
csearch::get_type_param_count(ccx.sess.cstore, m_id)
csearch::get_type_param_count(ccx.sess.cstore, m_id) -
csearch::get_type_param_count(ccx.sess.cstore, i_id)
}
}
@ -115,7 +117,7 @@ fn trans_monomorphized_callee(bcx: block, callee_id: ast::node_id,
let ccx = bcx.ccx();
let mname = ty::iface_methods(ccx.tcx, iface_id)[n_method].ident;
let mth_id = method_with_name(bcx.ccx(), impl_did, mname);
let n_m_tps = method_ty_param_count(ccx, mth_id);
let n_m_tps = method_ty_param_count(ccx, mth_id, impl_did);
let node_substs = node_id_type_params(bcx, callee_id);
let ty_substs = impl_substs +
vec::tailn(node_substs, node_substs.len() - n_m_tps);

View File

@ -0,0 +1,9 @@
import iter::*;
fn main() {
let range = bind uint::range(0u, 1000u, _);
let filt = bind iter::filter(range, {|&&n: uint| n % 3u != 0u && n % 5u != 0u }, _);
let sum = iter::foldl(filt, 0u) {|accum, &&n: uint| accum + n };
io::println(#fmt("%u", sum));
}