@@ -294,20 +294,52 @@ fn trans_static_method_callee(bcx: block,
294294}
295295
296296fn method_from_methods(ms: ~[@ast::method], name: ast::ident)
297- -> ast::def_id {
298- local_def(option::get(vec:: find(ms, |m| m.ident == name)).id )
297+ -> Option< ast::def_id> {
298+ ms. find(|m| m.ident == name).map(|m| local_def(m.id) )
299299}
300300
301301fn method_with_name(ccx: @crate_ctxt, impl_id: ast::def_id,
302302 name: ast::ident) -> ast::def_id {
303303 if impl_id.crate == ast::local_crate {
304304 match ccx.tcx.items.get(impl_id.node) {
305305 ast_map::node_item(@{node: ast::item_impl(_, _, _, ms), _}, _) => {
306- method_from_methods(ms, name)
306+ method_from_methods(ms, name).get()
307307 }
308308 ast_map::node_item(@{node:
309309 ast::item_class(struct_def, _), _}, _) => {
310- method_from_methods(struct_def.methods, name)
310+ method_from_methods(struct_def.methods, name).get()
311+ }
312+ _ => fail ~" method_with_name"
313+ }
314+ } else {
315+ csearch::get_impl_method(ccx.sess.cstore, impl_id, name)
316+ }
317+ }
318+
319+ fn method_with_name_or_default(ccx: @crate_ctxt, impl_id: ast::def_id,
320+ name: ast::ident) -> ast::def_id {
321+ if impl_id.crate == ast::local_crate {
322+ match ccx.tcx.items.get(impl_id.node) {
323+ ast_map::node_item(@{node: ast::item_impl(_, _, _, ms), _}, _) => {
324+ let did = method_from_methods(ms, name);
325+ if did.is_some() {
326+ return did.get();
327+ } else {
328+ // Look for a default method
329+ let pmm = ccx.tcx.provided_methods;
330+ match pmm.find(impl_id) {
331+ Some(pmis) => {
332+ for pmis.each |pmi| {
333+ if pmi.method_info.ident == name {
334+ debug!(" XXX %?", pmi.method_info.did);
335+ return pmi.method_info.did;
336+ }
337+ }
338+ fail
339+ }
340+ None => fail
341+ }
342+ }
311343 }
312344 _ => fail ~" method_with_name"
313345 }
@@ -318,10 +350,22 @@ fn method_with_name(ccx: @crate_ctxt, impl_id: ast::def_id,
318350
319351fn method_ty_param_count(ccx: @crate_ctxt, m_id: ast::def_id,
320352 i_id: ast::def_id) -> uint {
353+ debug!(" mythod_ty_param_count: m_id: %?, i_id: %?", m_id, i_id);
321354 if m_id.crate == ast::local_crate {
322- match ccx.tcx.items.get(m_id.node) {
323- ast_map::node_method(m, _, _) => vec::len(m.tps),
324- _ => fail ~" method_ty_param_count"
355+ match ccx.tcx.items.find(m_id.node) {
356+ Some(ast_map::node_method(m, _, _)) => m.tps.len(),
357+ None => {
358+ match ccx.tcx.provided_method_sources.find(m_id) {
359+ Some(source) => {
360+ method_ty_param_count(ccx, source.method_id, source.impl_id)
361+ }
362+ None => fail
363+ }
364+ }
365+ Some(ast_map::node_trait_method(@ast::provided(@m), _, _)) => {
366+ m.tps.len()
367+ }
368+ e => fail fmt!(" method_ty_param_count %?", e)
325369 }
326370 } else {
327371 csearch::get_type_param_count(ccx.sess.cstore, m_id) -
@@ -343,7 +387,8 @@ fn trans_monomorphized_callee(bcx: block,
343387 typeck::vtable_static(impl_did, rcvr_substs, rcvr_origins) => {
344388 let ccx = bcx.ccx();
345389 let mname = ty::trait_methods(ccx.tcx, trait_id)[n_method].ident;
346- let mth_id = method_with_name(bcx.ccx(), impl_did, mname);
390+ let mth_id = method_with_name_or_default(
391+ bcx.ccx(), impl_did, mname);
347392
348393 // obtain the `self` value:
349394 let Result {bcx, val: llself_val} =
0 commit comments