Skip to content

Commit b00abd0

Browse files
committed
Record type annotations for methods.
1 parent c44c7c5 commit b00abd0

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

src/comp/middle/typeck.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,13 +621,51 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) {
621621
ret @fold.respan[ast.item_](sp, item);
622622
}
623623

624+
fn get_ctor_obj_methods(@ty t) -> vec[method] {
625+
alt (t.struct) {
626+
case (ty_fn(_,?tobj)) {
627+
alt (tobj.struct) {
628+
case (ty_obj(?tm)) {
629+
ret tm;
630+
}
631+
case (_) {
632+
let vec[method] tm = vec();
633+
ret tm;
634+
}
635+
}
636+
}
637+
case (_) {
638+
let vec[method] tm = vec();
639+
ret tm;
640+
}
641+
}
642+
}
643+
644+
624645
fn fold_item_obj(&@env e, &span sp, ast.ident i,
625646
&ast._obj ob, vec[ast.ty_param] ty_params,
626647
ast.def_id id, ast.ann a) -> @ast.item {
627648
check (e.item_to_ty.contains_key(id));
628649
auto ty = e.item_to_ty.get(id);
629-
auto item = ast.item_obj(i, ob, ty_params, id,
630-
ast.ann_type(ty));
650+
let vec[method] meth_tys = get_ctor_obj_methods(ty);
651+
let vec[@ast.method] methods = vec();
652+
653+
let uint n = 0u;
654+
for (method meth_ty in meth_tys) {
655+
let @ast.method meth = ob.methods.(n);
656+
let ast.method_ m_;
657+
let @ast.method m;
658+
auto meth_tfn = plain_ty(ty_fn(meth_ty.inputs,
659+
meth_ty.output));
660+
m_ = rec(ann=ast.ann_type(meth_tfn) with meth.node);
661+
m = @rec(node=m_ with *meth);
662+
append[@ast.method](methods, m);
663+
n += 1u;
664+
}
665+
666+
auto ob_ = rec(methods = methods with ob);
667+
auto item = ast.item_obj(i, ob_, ty_params, id,
668+
ast.ann_type(ty));
631669
ret @fold.respan[ast.item_](sp, item);
632670
}
633671

0 commit comments

Comments
 (0)