about summary refs log tree commit diff
path: root/src/comp/syntax
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2012-02-20 15:42:21 -0800
committerTim Chevalier <chevalier@alum.wellesley.edu>2012-02-20 17:16:52 -0800
commit2299d204e40e565396daabc7b8d5141cdef52c8b (patch)
treed44318a7c1a3ca7d7d6e93a020626538c0a4b0e0 /src/comp/syntax
parent5837e1e809af6d783984d94ca27fe488823ecfe6 (diff)
downloadrust-2299d204e40e565396daabc7b8d5141cdef52c8b.tar.gz
rust-2299d204e40e565396daabc7b8d5141cdef52c8b.zip
Further work on resolving and typechecking classes
Class tests aren't working yet, but they fail a little later :-)

Also, make the parser correctly set a constructor's result type to
its enclosing class type.
Diffstat (limited to 'src/comp/syntax')
-rw-r--r--src/comp/syntax/parse/parser.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index eb34fb4b89d..35d5119c4e6 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -1972,13 +1972,14 @@ fn parse_item_res(p: parser, attrs: [ast::attribute]) -> @ast::item {
 fn parse_item_class(p: parser, attrs: [ast::attribute]) -> @ast::item {
     let lo = p.last_span.lo;
     let class_name = parse_value_ident(p);
+    let class_path = ident_to_path(p.last_span, class_name);
     let ty_params = parse_ty_params(p);
     expect(p, token::LBRACE);
     let items: [@ast::class_item] = [];
     let ctor_id = p.get_id();
     let the_ctor : option<(ast::fn_decl, ast::blk)> = none;
     while p.token != token::RBRACE {
-       alt parse_class_item(p) {
+        alt parse_class_item(p, class_path) {
             ctor_decl(a_fn_decl, blk) {
                 the_ctor = some((a_fn_decl, blk));
             }
@@ -2015,10 +2016,14 @@ enum class_contents { ctor_decl(ast::fn_decl, ast::blk),
                       // none of these are a ctor decl
                       priv_decls([ast::class_member])}
 
-fn parse_class_item(p:parser) -> class_contents {
+    fn parse_class_item(p:parser, class_name:@ast::path) -> class_contents {
     if eat_word(p, "new") {
         // Can ctors have attrs?
-        let decl = parse_fn_decl(p, ast::impure_fn);
+            // result type is always the type of the class
+        let decl_ = parse_fn_decl(p, ast::impure_fn);
+        let decl = {output: @{node: ast::ty_path(class_name, p.get_id()),
+                                  span: decl_.output.span}
+                    with decl_};
         let body = parse_block(p);
         ret ctor_decl(decl, body);
     }