Skip to content

Commit 7e4d95c

Browse files
committed
---
yaml --- r: 2046 b: refs/heads/master c: 573bc5a h: refs/heads/master v: v3
1 parent ac8701c commit 7e4d95c

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 535581185921ebb2602d4f42604e54436052fc1f
2+
refs/heads/master: 573bc5ad0190e2c309d13d5d2268d117c3cf2947

trunk/src/comp/middle/typeck.rs

+32-3
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,8 @@ fn demand_block(&@fn_ctxt fcx, @ty.t expected, &ast.block bloc) -> ast.block {
14411441
}
14421442
}
14431443

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.
14451446

14461447
fn writeback_local(&option.t[@fn_ctxt] env, &span sp, @ast.local local)
14471448
-> @ast.decl {
@@ -1458,7 +1459,32 @@ fn writeback_local(&option.t[@fn_ctxt] env, &span sp, @ast.local local)
14581459
ret @fold.respan[ast.decl_](sp, ast.decl_local(local_wb));
14591460
}
14601461

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 {
14621488
fn update_env_for_item(&option.t[@fn_ctxt] env, @ast.item i)
14631489
-> option.t[@fn_ctxt] {
14641490
ret none[@fn_ctxt];
@@ -1467,12 +1493,15 @@ fn writeback(&@fn_ctxt fcx, &ast.block block) -> ast.block {
14671493
ret !option.is_none[@fn_ctxt](env);
14681494
}
14691495

1496+
// FIXME: rustboot bug prevents us from using these functions directly
14701497
auto fld = fold.new_identity_fold[option.t[@fn_ctxt]]();
14711498
auto wbl = writeback_local;
1499+
auto rltia = resolve_local_types_in_annotation;
14721500
auto uefi = update_env_for_item;
14731501
auto kg = keep_going;
14741502
fld = @rec(
14751503
fold_decl_local = wbl,
1504+
fold_ann = rltia,
14761505
update_env_for_item = uefi,
14771506
keep_going = kg
14781507
with *fld
@@ -2596,7 +2625,7 @@ fn check_fn(&@crate_ctxt ccx, &ast.fn_decl decl, ast.proto proto,
25962625

25972626
// TODO: Make sure the type of the block agrees with the function type.
25982627
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);
26002629

26012630
auto fn_t = rec(decl=decl,
26022631
proto=proto,

0 commit comments

Comments
 (0)