@@ -34,6 +34,8 @@ import std.option;
34
34
import std. option . none ;
35
35
import std. option . some ;
36
36
37
+ import pretty. pprust ;
38
+
37
39
import util. typestate_ann . ts_ann ;
38
40
39
41
type ty_table = hashmap [ ast. def_id , @ty. t] ;
@@ -49,6 +51,7 @@ type crate_ctxt = rec(session.session sess,
49
51
ty. type_cache type_cache ,
50
52
@ty_item_table item_items ,
51
53
vec[ ast. obj_field] obj_fields ,
54
+ option. t[ ast. def_id] this_obj ,
52
55
mutable int next_var_id ) ;
53
56
54
57
type fn_ctxt = rec ( @ty. t ret_ty ,
@@ -1242,10 +1245,9 @@ fn demand_expr_full(&@fn_ctxt fcx, @ty.t expected, @ast.expr e,
1242
1245
ann_to_type( ann) , adk) ;
1243
1246
e_1 = ast. expr_call( sube, es, triv_ann( t) ) ;
1244
1247
}
1245
- case ( ast. expr_call_self( ?sube, ?es, ?ann) ) {
1246
- auto t = demand_full( fcx, e. span, expected,
1247
- ann_to_type( ann) , adk) ;
1248
- e_1 = ast. expr_call_self( sube, es, triv_ann( t) ) ;
1248
+ case ( ast. expr_self_method( ?id, ?ann) ) {
1249
+ auto t = demand( fcx, e. span, expected, ann_to_type( ann) ) ;
1250
+ e_1 = ast. expr_self_method( id, triv_ann( t) ) ;
1249
1251
}
1250
1252
case ( ast. expr_binary( ?bop, ?lhs, ?rhs, ?ann) ) {
1251
1253
auto t = demand( fcx, e. span, expected, ann_to_type( ann) ) ;
@@ -1572,6 +1574,8 @@ fn check_pat(&@fn_ctxt fcx, @ast.pat pat) -> @ast.pat {
1572
1574
}
1573
1575
1574
1576
fn check_expr( & @fn_ctxt fcx, @ast. expr expr) -> @ast. expr {
1577
+ // log "typechecking expr " + pretty.pprust.expr_to_str(expr);
1578
+
1575
1579
// A generic function to factor out common logic from call and bind
1576
1580
// expressions.
1577
1581
fn check_call_or_bind( & @fn_ctxt fcx, & @ast. expr f,
@@ -2125,16 +2129,44 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
2125
2129
ast. expr_call( f_1, args_1, ann) ) ;
2126
2130
}
2127
2131
2128
- case ( ast. expr_call_self ( ?ident , ?args , _) ) {
2129
- // FIXME: What's to check here?
2132
+ case ( ast. expr_self_method ( ?id , _) ) {
2133
+ auto t = plain_ty( ty. ty_nil) ;
2134
+ let @ty. t this_obj_ty;
2135
+
2136
+ // Grab the type of the current object
2137
+ auto this_obj_id = fcx. ccx. this_obj;
2138
+ alt ( this_obj_id) {
2139
+ case ( some[ ast. def_id] ( ?def_id ) ) {
2140
+ auto this_obj_tpt = fcx. ccx. type_cache. find( def_id) ;
2141
+ alt ( this_obj_tpt) {
2142
+ case ( some[ ty_params_opt_and_ty] ( ?tpt ) ) {
2143
+ this_obj_ty = tpt. _1;
2144
+ }
2145
+ case ( _) { fail; }
2146
+ }
2147
+ }
2148
+ case ( _) { fail; }
2149
+ }
2150
+
2130
2151
2131
- // FIXME: These two lines are ripped off from the expr_call case;
2132
- // what should they be really?
2133
- auto rt_1 = plain_ty( ty. ty_nil) ;
2134
- auto ann = triv_ann( rt_1) ;
2152
+ // Grab this method's type out of the current object type
2153
+
2154
+ // this_obj_ty is an @ty.t
2155
+ alt ( this_obj_ty. struct ) {
2156
+ case ( ty. ty_obj ( ?methods ) ) {
2157
+ for ( ty. method method in methods) {
2158
+ if ( method. ident == id) {
2159
+ t = ty. method_ty_to_fn_ty( method) ;
2160
+ }
2161
+ }
2162
+ }
2163
+ case ( _) { fail; }
2164
+ }
2165
+
2166
+ auto ann = triv_ann( t) ;
2135
2167
2136
2168
ret @fold. respan[ ast. expr_] ( expr. span,
2137
- ast. expr_call_self ( ident , args , ann) ) ;
2169
+ ast. expr_self_method ( id , ann) ) ;
2138
2170
}
2139
2171
2140
2172
case ( ast. expr_spawn ( ?dom , ?name , ?f , ?args , _) ) {
@@ -2596,8 +2628,10 @@ fn check_item_fn(&@crate_ctxt ccx, &span sp, ast.ident ident, &ast._fn f,
2596
2628
2597
2629
fn update_obj_fields ( & @crate_ctxt ccx , @ast. item i ) -> @crate_ctxt {
2598
2630
alt ( i. node ) {
2599
- case ( ast. item_obj ( _, ?ob, _, _, _) ) {
2600
- ret @rec( obj_fields = ob. fields with * ccx) ;
2631
+ case ( ast. item_obj ( _, ?ob, _, ?obj_def_ids, _) ) {
2632
+ let ast. def_id di = obj_def_ids. ty ;
2633
+ ret @rec( obj_fields = ob. fields ,
2634
+ this_obj = some[ ast. def_id ] ( di) with * ccx) ;
2601
2635
}
2602
2636
case ( _) {
2603
2637
}
@@ -2617,6 +2651,7 @@ fn check_crate(session.session sess, @ast.crate crate) -> typecheck_result {
2617
2651
type_cache=result. _1 ,
2618
2652
item_items=result. _2 ,
2619
2653
obj_fields=fields,
2654
+ this_obj=none[ ast. def_id ] ,
2620
2655
mutable next_var_id=0 ) ;
2621
2656
2622
2657
auto fld = fold. new_identity_fold [ @crate_ctxt] ( ) ;
0 commit comments