@@ -2051,13 +2051,23 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr,
2051
2051
}
2052
2052
ast:: expr_fn ( f) {
2053
2053
let cx = @{ tcx: tcx} ;
2054
- let convert =
2055
- bind ast_ty_to_ty ( cx. tcx , bind collect:: getter ( cx, _) , _) ;
2056
- let ty_of_arg = bind collect:: ty_of_arg ( cx, _) ;
2054
+ let convert = bind ast_ty_to_ty_crate_tyvar ( fcx, _) ;
2055
+ let ty_of_arg = lambda ( a: & ast:: arg) -> ty:: arg {
2056
+ let ty_mode = ast_mode_to_mode ( a. mode ) ;
2057
+ let tt = ast_ty_to_ty_crate_tyvar ( fcx, a. ty ) ;
2058
+ ret { mode : ty_mode, ty : tt} ;
2059
+ } ;
2057
2060
let fty =
2058
2061
collect:: ty_of_fn_decl ( cx, convert, ty_of_arg, f. decl , f. proto ,
2059
2062
~[ ] , none) . ty ;
2060
2063
write:: ty_only_fixup ( fcx, id, fty) ;
2064
+
2065
+ // Unify the type of the function with the expected type before we
2066
+ // typecheck the body so that we have more information about the
2067
+ // argument types in the body. This is needed to make binops and
2068
+ // record projection work on type inferred arguments.
2069
+ unify ( fcx, expr. span , expected, fty) ;
2070
+
2061
2071
check_fn ( fcx. ccx , f, id, some ( fcx) ) ;
2062
2072
}
2063
2073
ast:: expr_block ( b) {
@@ -2611,7 +2621,7 @@ fn check_fn(ccx: &@crate_ctxt, f: &ast::_fn, id: &ast::node_id,
2611
2621
let gather_result = gather_locals ( ccx, f, id, old_fcx) ;
2612
2622
let fixups: [ ast:: node_id ] = ~[ ] ;
2613
2623
let fcx: @fn_ctxt =
2614
- @{ ret_ty: ast_ty_to_ty_crate ( ccx, decl . output ) ,
2624
+ @{ ret_ty: ty :: ty_fn_ret ( ccx. tcx , ty :: node_id_to_type ( ccx . tcx , id ) ) ,
2615
2625
purity: decl. purity ,
2616
2626
proto: f. proto ,
2617
2627
var_bindings: gather_result. var_bindings ,
0 commit comments