about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2010-12-15 17:04:07 -0800
committerGraydon Hoare <graydon@mozilla.com>2010-12-15 17:04:21 -0800
commit482dc0c8fa492bd533fb33a20d4cbb5677e73a8a (patch)
tree18d9081b2ba7a1f4e0cd01707c08a3855bd2b96b /src
parente17473de07f2f543d2c4fecd1212b1a716a33559 (diff)
downloadrust-482dc0c8fa492bd533fb33a20d4cbb5677e73a8a.tar.gz
rust-482dc0c8fa492bd533fb33a20d4cbb5677e73a8a.zip
Convert obj item type to ctor type rather than obj type.
Diffstat (limited to 'src')
-rw-r--r--src/comp/middle/typeck.rs37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index c3fafd570be..b58b874fae1 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -417,6 +417,30 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) {
         ret rec(ident=m.node.ident, inputs=inputs, output=output);
     }
 
+    fn ty_of_obj(@ty_item_table id_to_ty_item,
+                 @ty_table item_to_ty,
+                 &ast._obj obj_info) -> @ty {
+        auto f = bind ty_of_method(id_to_ty_item, item_to_ty, _);
+        auto methods =
+            _vec.map[@ast.method,method](f, obj_info.methods);
+
+        auto t_obj = plain_ty(ty_obj(methods));
+        ret t_obj;
+    }
+
+    fn ty_of_obj_ctor(@ty_item_table id_to_ty_item,
+                      @ty_table item_to_ty,
+                      &ast._obj obj_info) -> @ty {
+        auto t_obj = ty_of_obj(id_to_ty_item, item_to_ty, obj_info);
+        let vec[arg] t_inputs = vec();
+        for (ast.obj_field f in obj_info.fields) {
+            auto t_field = getter(id_to_ty_item, item_to_ty, f.id);
+            append[arg](t_inputs, rec(mode=ast.alias, ty=t_field));
+        }
+        auto t_fn = plain_ty(ty_fn(t_inputs, t_obj));
+        ret t_fn;
+    }
+
     fn ty_of_item(@ty_item_table id_to_ty_item,
                   @ty_table item_to_ty,
                   @ast.item it) -> @ty {
@@ -444,14 +468,11 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) {
 
             case (ast.item_obj(?ident, ?obj_info, _, ?def_id, _)) {
                 // TODO: handle ty-params
-
-                auto f = bind ty_of_method(id_to_ty_item, item_to_ty, _);
-                auto methods =
-                    _vec.map[@ast.method,method](f, obj_info.methods);
-
-                auto t_obj = plain_ty(ty_obj(methods));
-                item_to_ty.insert(def_id, t_obj);
-                ret t_obj;
+                auto t_ctor = ty_of_obj_ctor(id_to_ty_item,
+                                             item_to_ty,
+                                             obj_info);
+                item_to_ty.insert(def_id, t_ctor);
+                ret t_ctor;
             }
 
             case (ast.item_ty(?ident, ?ty, _, ?def_id, _)) {