mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 13:05:18 +03:00
Typecheck block tail expressions that are fn return values
This commit is contained in:
@@ -2331,7 +2331,6 @@ fn check_fn(&@crate_ctxt ccx, &ast::fn_decl decl, ast::proto proto,
|
||||
mutable next_var_id=gather_result.next_var_id,
|
||||
mutable fixups=fixups,
|
||||
ccx=ccx);
|
||||
// TODO: Make sure the type of the block agrees with the function type.
|
||||
|
||||
check_block(fcx, body);
|
||||
alt (decl.purity) {
|
||||
@@ -2346,7 +2345,19 @@ fn check_fn(&@crate_ctxt ccx, &ast::fn_decl decl, ast::proto proto,
|
||||
}
|
||||
case (_) { }
|
||||
}
|
||||
|
||||
writeback::resolve_type_vars_in_block(fcx, body);
|
||||
|
||||
if (option::is_some(body.node.expr)) {
|
||||
auto tail_expr = option::get(body.node.expr);
|
||||
auto tail_expr_ty = expr_ty(ccx.tcx, tail_expr);
|
||||
// Have to exclude ty_nil to allow functions to end in
|
||||
// while expressions, etc.
|
||||
if (!ty::type_is_nil(ccx.tcx, tail_expr_ty)) {
|
||||
demand::simple(fcx, tail_expr.span,
|
||||
fcx.ret_ty, tail_expr_ty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_method(&@crate_ctxt ccx, &@ast::method method) {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// xfail-stage0
|
||||
// error-pattern:mismatched types
|
||||
|
||||
fn f() -> int {
|
||||
true
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
Reference in New Issue
Block a user