@@ -106,17 +106,31 @@ fn method_with_name(ccx: @crate_ctxt, impl_id: ast::def_id,
106
106
}
107
107
}
108
108
109
+ fn method_ty_param_count ( ccx : crate_ctxt , m_id : ast:: def_id ) -> uint {
110
+ if m_id. crate == ast:: local_crate {
111
+ alt check ccx. tcx . items . get ( m_id. node ) {
112
+ ast_map:: node_method ( m, _, _) { vec:: len ( m. tps ) }
113
+ }
114
+ } else {
115
+ csearch:: get_type_param_count ( ccx. sess . cstore , m_id)
116
+ }
117
+ }
118
+
109
119
fn trans_monomorphized_callee ( bcx : block , callee_id : ast:: node_id ,
110
120
base : @ast:: expr , iface_id : ast:: def_id ,
111
121
n_method : uint , n_param : uint , n_bound : uint ,
112
122
substs : param_substs ) -> lval_maybe_callee {
113
123
alt find_vtable_in_fn_ctxt ( substs, n_param, n_bound) {
114
- typeck:: vtable_static ( impl_did, tys , sub_origins) {
115
- let tcx = bcx. tcx ( ) ;
116
- let mname = ty:: iface_methods ( tcx, iface_id) [ n_method] . ident ;
124
+ typeck:: vtable_static ( impl_did, impl_substs , sub_origins) {
125
+ let ccx = bcx. ccx ( ) ;
126
+ let mname = ty:: iface_methods ( ccx . tcx , iface_id) [ n_method] . ident ;
117
127
let mth_id = method_with_name ( bcx. ccx ( ) , impl_did, mname) ;
128
+ let n_m_tps = method_ty_param_count ( ccx, mth_id) ;
129
+ let node_substs = node_id_type_params ( bcx, callee_id) ;
130
+ let ty_substs = impl_substs +
131
+ vec:: tail_n ( node_substs, node_substs. len ( ) - n_m_tps) ;
118
132
ret trans_static_callee ( bcx, callee_id, base, mth_id,
119
- some ( ( tys , sub_origins) ) ) ;
133
+ some ( ( ty_substs , sub_origins) ) ) ;
120
134
}
121
135
typeck:: vtable_iface ( iid, tps) {
122
136
ret trans_iface_callee ( bcx, base, callee_id, n_method) ;
@@ -155,11 +169,11 @@ fn find_vtable_in_fn_ctxt(ps: param_substs, n_param: uint, n_bound: uint)
155
169
// Vtables are stored in a flat array, finding the right one is
156
170
// somewhat awkward
157
171
for bounds in * ps. bounds {
158
- i += 1 u;
159
172
if i >= n_param { break ; }
160
173
for bound in * bounds {
161
174
alt bound { ty : : bound_iface ( _) { vtable_off += 1 u; } _ { } }
162
175
}
176
+ i += 1 u;
163
177
}
164
178
option:: get ( ps. vtables ) [ vtable_off]
165
179
}
0 commit comments