Skip to content

Commit

Permalink
Fix broken determination of external method type param count
Browse files Browse the repository at this point in the history
Closes #2185
  • Loading branch information
marijnh committed Apr 23, 2012
1 parent 5129275 commit dfdca5d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/rustc/middle/trans/base.rs
Expand Up @@ -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) {
Expand Down
8 changes: 5 additions & 3 deletions src/rustc/middle/trans/impl.rs
Expand Up @@ -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)
}
}

Expand All @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/test/run-pass/issue-2185.rs
@@ -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));
}

0 comments on commit dfdca5d

Please sign in to comment.