Skip to content

Commit 5495ad1

Browse files
msullivanbrson
authored andcommitted
Fix type inference inside of anonymous functions.
1 parent 860e8fd commit 5495ad1

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/comp/middle/typeck.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,8 +974,16 @@ mod writeback {
974974
fn visit_stmt_pre(@fn_ctxt fcx, &@ast::stmt s) {
975975
resolve_type_vars_for_node(fcx, s.span, ty::stmt_node_id(s));
976976
}
977-
fn visit_expr_pre(@fn_ctxt fcx, &@ast::expr e) {
977+
fn visit_expr_pre(@mutable bool ignore, @fn_ctxt fcx, &@ast::expr e) {
978978
resolve_type_vars_for_node(fcx, e.span, e.id);
979+
alt (e.node) {
980+
// We don't want to recurse down into lambdas.
981+
case (ast::expr_fn(_)) { *ignore = true; }
982+
case (_) { }
983+
}
984+
}
985+
fn visit_expr_post(@mutable bool ignore, &@ast::expr e) {
986+
*ignore = false;
979987
}
980988
fn visit_block_pre(@fn_ctxt fcx, &ast::block b) {
981989
resolve_type_vars_for_node(fcx, b.span, b.node.id);
@@ -1015,7 +1023,8 @@ mod writeback {
10151023
visit_item_pre=bind visit_item_pre(ignore, _),
10161024
visit_item_post=bind visit_item_post(ignore, _),
10171025
visit_stmt_pre=bind visit_stmt_pre(fcx, _),
1018-
visit_expr_pre=bind visit_expr_pre(fcx, _),
1026+
visit_expr_pre=bind visit_expr_pre(ignore, fcx, _),
1027+
visit_expr_post=bind visit_expr_post(ignore, _),
10191028
visit_block_pre=bind visit_block_pre(fcx, _),
10201029
visit_pat_pre=bind visit_pat_pre(fcx, _),
10211030
visit_local_pre=bind visit_local_pre(fcx, _)

src/test/run-pass/fn-type-infer.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// xfail-stage0
2+
3+
fn main() {
4+
// We should be able to type infer inside of lambdas.
5+
auto f = fn () { auto i = 10; };
6+
}

0 commit comments

Comments
 (0)