Skip to content

Commit 9676fb2

Browse files
committed
Assign method types properly by sorted-order.
1 parent 153efb5 commit 9676fb2

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/comp/middle/typeck.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ fn ast_ty_to_ty_crate(@crate_ctxt ccx, &@ast.ty ast_ty) -> @ty.t {
164164
// We then annotate the AST with the resulting types and return the annotated
165165
// AST, along with a table mapping item IDs to their types.
166166

167-
fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) {
167+
fn collect_item_types(session.session sess, @ast.crate crate)
168+
-> tup(@ast.crate, @ty_table) {
168169

169170
type ty_item_table = hashmap[ast.def_id,@ast.item];
170171

@@ -344,9 +345,11 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) {
344345
// Second pass: translate the types of all items.
345346
let @ty_table item_to_ty = @common.new_def_hash[@ty.t]();
346347

347-
type env = rec(@ty_item_table id_to_ty_item,
348+
type env = rec(session.session sess,
349+
@ty_item_table id_to_ty_item,
348350
@ty_table item_to_ty);
349-
let @env e = @rec(id_to_ty_item=id_to_ty_item,
351+
let @env e = @rec(sess=sess,
352+
id_to_ty_item=id_to_ty_item,
350353
item_to_ty=item_to_ty);
351354

352355
fn convert(&@env e, @ast.item i) -> @env {
@@ -413,17 +416,18 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) {
413416
let vec[@ast.method] methods = vec();
414417
let vec[ast.obj_field] fields = vec();
415418

416-
let uint n = 0u;
417-
for (method meth_ty in meth_tys) {
418-
let @ast.method meth = ob.methods.(n);
419+
for (@ast.method meth in ob.methods) {
420+
let uint ix = ty.method_idx(e.sess,
421+
sp, meth.node.ident,
422+
meth_tys);
423+
let method meth_ty = meth_tys.(ix);
419424
let ast.method_ m_;
420425
let @ast.method m;
421426
auto meth_tfn = plain_ty(ty.ty_fn(meth_ty.inputs,
422427
meth_ty.output));
423428
m_ = rec(ann=ast.ann_type(meth_tfn) with meth.node);
424429
m = @rec(node=m_ with *meth);
425430
append[@ast.method](methods, m);
426-
n += 1u;
427431
}
428432
auto g = bind getter(e.id_to_ty_item, e.item_to_ty, _);
429433
for (ast.obj_field fld in ob.fields) {
@@ -1529,7 +1533,7 @@ fn update_obj_fields(&@crate_ctxt ccx, @ast.item i) -> @crate_ctxt {
15291533
}
15301534

15311535
fn check_crate(session.session sess, @ast.crate crate) -> @ast.crate {
1532-
auto result = collect_item_types(crate);
1536+
auto result = collect_item_types(sess, crate);
15331537

15341538
let vec[ast.obj_field] fields = vec();
15351539

0 commit comments

Comments
 (0)