@@ -1441,7 +1441,8 @@ fn demand_block(&@fn_ctxt fcx, @ty.t expected, &ast.block bloc) -> ast.block {
1441
1441
}
1442
1442
}
1443
1443
1444
- // Writeback: the phase that writes inferred types back into the AST.
1444
+ // Local variable resolution: the phase that finds all the types in the AST
1445
+ // and replaces opaque "ty_local" types with the resolved local types.
1445
1446
1446
1447
fn writeback_local( & option. t[ @fn_ctxt] env, & span sp, @ast. local local)
1447
1448
-> @ast. decl {
@@ -1458,7 +1459,32 @@ fn writeback_local(&option.t[@fn_ctxt] env, &span sp, @ast.local local)
1458
1459
ret @fold. respan[ ast. decl_] ( sp, ast. decl_local( local_wb) ) ;
1459
1460
}
1460
1461
1461
- fn writeback( & @fn_ctxt fcx, & ast. block block) -> ast. block {
1462
+ fn resolve_local_types_in_annotation( & option. t[ @fn_ctxt] env, ast. ann ann)
1463
+ -> ast. ann {
1464
+ state obj folder( @fn_ctxt fcx) {
1465
+ fn fold_simple_ty( @ty. t typ) -> @ty. t {
1466
+ alt ( typ. struct ) {
1467
+ case ( ty. ty_local( ?lid) ) { ret fcx. locals. get( lid) ; }
1468
+ case ( _) { ret typ; }
1469
+ }
1470
+ }
1471
+ }
1472
+
1473
+ auto fcx = option. get[ @fn_ctxt] ( env) ;
1474
+ alt ( ann) {
1475
+ case ( ast. ann_none) {
1476
+ log "warning: no type for expression" ;
1477
+ ret ann;
1478
+ }
1479
+ case ( ast. ann_type( ?typ, ?tps, ?ts_info) ) {
1480
+ auto new_type = ty. fold_ty( folder( fcx) , ann_to_type( ann) ) ;
1481
+ ret ast. ann_type( new_type, tps, ts_info) ;
1482
+ }
1483
+ }
1484
+ }
1485
+
1486
+ fn resolve_local_types_in_block( & @fn_ctxt fcx, & ast. block block)
1487
+ -> ast. block {
1462
1488
fn update_env_for_item( & option. t[ @fn_ctxt] env, @ast. item i)
1463
1489
-> option. t[ @fn_ctxt] {
1464
1490
ret none[ @fn_ctxt] ;
@@ -1467,12 +1493,15 @@ fn writeback(&@fn_ctxt fcx, &ast.block block) -> ast.block {
1467
1493
ret !option. is_none[ @fn_ctxt] ( env) ;
1468
1494
}
1469
1495
1496
+ // FIXME: rustboot bug prevents us from using these functions directly
1470
1497
auto fld = fold. new_identity_fold[ option. t[ @fn_ctxt] ] ( ) ;
1471
1498
auto wbl = writeback_local;
1499
+ auto rltia = resolve_local_types_in_annotation;
1472
1500
auto uefi = update_env_for_item;
1473
1501
auto kg = keep_going;
1474
1502
fld = @rec(
1475
1503
fold_decl_local = wbl,
1504
+ fold_ann = rltia,
1476
1505
update_env_for_item = uefi,
1477
1506
keep_going = kg
1478
1507
with * fld
@@ -2596,7 +2625,7 @@ fn check_fn(&@crate_ctxt ccx, &ast.fn_decl decl, ast.proto proto,
2596
2625
2597
2626
// TODO: Make sure the type of the block agrees with the function type.
2598
2627
auto block_t = check_block ( fcx, body) ;
2599
- auto block_wb = writeback ( fcx, block_t) ;
2628
+ auto block_wb = resolve_local_types_in_block ( fcx, block_t) ;
2600
2629
2601
2630
auto fn_t = rec ( decl=decl,
2602
2631
proto=proto,
0 commit comments