Skip to content

Fix type inference inside of anonymous functions. #567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,8 +974,16 @@ mod writeback {
fn visit_stmt_pre(@fn_ctxt fcx, &@ast::stmt s) {
resolve_type_vars_for_node(fcx, s.span, ty::stmt_node_id(s));
}
fn visit_expr_pre(@fn_ctxt fcx, &@ast::expr e) {
fn visit_expr_pre(@mutable bool ignore, @fn_ctxt fcx, &@ast::expr e) {
resolve_type_vars_for_node(fcx, e.span, e.id);
alt (e.node) {
// We don't want to recurse down into lambdas.
case (ast::expr_fn(_)) { *ignore = true; }
case (_) { }
}
}
fn visit_expr_post(@mutable bool ignore, &@ast::expr e) {
*ignore = false;
}
fn visit_block_pre(@fn_ctxt fcx, &ast::block b) {
resolve_type_vars_for_node(fcx, b.span, b.node.id);
Expand Down Expand Up @@ -1015,7 +1023,8 @@ mod writeback {
visit_item_pre=bind visit_item_pre(ignore, _),
visit_item_post=bind visit_item_post(ignore, _),
visit_stmt_pre=bind visit_stmt_pre(fcx, _),
visit_expr_pre=bind visit_expr_pre(fcx, _),
visit_expr_pre=bind visit_expr_pre(ignore, fcx, _),
visit_expr_post=bind visit_expr_post(ignore, _),
visit_block_pre=bind visit_block_pre(fcx, _),
visit_pat_pre=bind visit_pat_pre(fcx, _),
visit_local_pre=bind visit_local_pre(fcx, _)
Expand Down
6 changes: 6 additions & 0 deletions src/test/run-pass/fn-type-infer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// xfail-stage0

fn main() {
// We should be able to type infer inside of lambdas.
auto f = fn () { auto i = 10; };
}