@@ -33,6 +33,7 @@ import std.option.some;
33
33
type ty_table = hashmap [ ast. def_id , @ty. t] ;
34
34
type crate_ctxt = rec ( session . session sess,
35
35
@ty_table item_types ,
36
+ vec[ ast. obj_field] obj_fields ,
36
37
mutable int next_var_id ) ;
37
38
38
39
type fn_ctxt = rec ( @ty. t ret_ty ,
@@ -410,6 +411,7 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) {
410
411
auto t = e. item_to_ty. get( id) ;
411
412
let vec[ method] meth_tys = get_ctor_obj_methods( t) ;
412
413
let vec[ @ast. method] methods = vec( ) ;
414
+ let vec[ ast. obj_field] fields = vec( ) ;
413
415
414
416
let uint n = 0 u;
415
417
for ( method meth_ty in meth_tys) {
@@ -423,8 +425,16 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) {
423
425
append[ @ast. method] ( methods, m) ;
424
426
n += 1 u;
425
427
}
428
+ auto g = bind getter( e. id_to_ty_item, e. item_to_ty, _) ;
429
+ for ( ast. obj_field fld in ob. fields) {
430
+ let @ty. t fty = ast_ty_to_ty( g, fld. ty) ;
431
+ let ast. obj_field f = rec( ann=ast. ann_type( fty) with fld) ;
432
+ append[ ast. obj_field] ( fields, f) ;
433
+ }
426
434
427
- auto ob_ = rec( methods = methods with ob) ;
435
+ auto ob_ = rec( methods = methods,
436
+ fields = fields
437
+ with ob) ;
428
438
auto item = ast. item_obj( i, ob_, ty_params, id,
429
439
ast. ann_type( t) ) ;
430
440
ret @fold. respan[ ast. item_] ( sp, item) ;
@@ -915,6 +925,10 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
915
925
case ( none[ @ty. t] ) { t = plain_ty( ty. ty_local( id) ) ; }
916
926
}
917
927
}
928
+ case ( ast. def_obj_field( ?id) ) {
929
+ check ( fcx. locals. contains_key( id) ) ;
930
+ t = fcx. locals. get( id) ;
931
+ }
918
932
case ( ast. def_fn( ?id) ) {
919
933
check ( fcx. ccx. item_types. contains_key( id) ) ;
920
934
t = generalize_ty( fcx. ccx, fcx. ccx. item_types. get( id) ) ;
@@ -1456,11 +1470,18 @@ fn check_fn(&@crate_ctxt ccx, ast.effect effect,
1456
1470
// and return type translated to typeck.ty values. We don't need do to it
1457
1471
// again here, we can extract them.
1458
1472
1473
+
1474
+ for ( ast. obj_field f in ccx. obj_fields) {
1475
+ auto field_ty = ty. ann_to_type( f. ann) ;
1476
+ local_ty_table. insert( f. id, field_ty) ;
1477
+ }
1478
+
1459
1479
// Store the type of each argument in the table.
1460
1480
for ( ast. arg arg in inputs) {
1461
1481
auto input_ty = ast_ty_to_ty_crate( ccx, arg. ty) ;
1462
1482
local_ty_table. insert( arg. id, input_ty) ;
1463
1483
}
1484
+
1464
1485
let @fn_ctxt fcx = @rec( ret_ty = ast_ty_to_ty_crate( ccx, output) ,
1465
1486
locals = local_ty_table,
1466
1487
ccx = ccx) ;
@@ -1496,14 +1517,31 @@ fn check_item_fn(&@crate_ctxt ccx, &span sp, ast.ident ident, &ast._fn f,
1496
1517
ret @fold. respan[ ast. item_] ( sp, item) ;
1497
1518
}
1498
1519
1520
+ fn update_obj_fields( & @crate_ctxt ccx, @ast. item i) -> @crate_ctxt {
1521
+ alt ( i. node) {
1522
+ case ( ast. item_obj( _, ?ob, _, _, _) ) {
1523
+ ret @rec( obj_fields = ob. fields with * ccx) ;
1524
+ }
1525
+ case ( _) {
1526
+ }
1527
+ }
1528
+ ret ccx;
1529
+ }
1530
+
1499
1531
fn check_crate( session. session sess, @ast. crate crate ) -> @ast. crate {
1500
1532
auto result = collect_item_types( crate ) ;
1501
1533
1502
- auto ccx = @rec( sess=sess, item_types=result. _1, mutable next_var_id=0 ) ;
1534
+ let vec[ ast. obj_field] fields = vec( ) ;
1535
+
1536
+ auto ccx = @rec( sess=sess,
1537
+ item_types=result. _1,
1538
+ obj_fields=fields,
1539
+ mutable next_var_id=0 ) ;
1503
1540
1504
1541
auto fld = fold. new_identity_fold[ @crate_ctxt] ( ) ;
1505
1542
1506
- fld = @rec( fold_fn = bind check_fn( _, _, _, _, _) ,
1543
+ fld = @rec( update_env_for_item = bind update_obj_fields( _, _) ,
1544
+ fold_fn = bind check_fn( _, _, _, _, _) ,
1507
1545
fold_item_fn = bind check_item_fn( _, _, _, _, _, _, _)
1508
1546
with * fld) ;
1509
1547
ret fold. fold_crate[ @crate_ctxt] ( ccx, fld, result. _0) ;
0 commit comments