mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 14:31:55 +00:00
Fix type inference of fn tail expressions. Closes #680
This commit is contained in:
parent
a38ba01fa4
commit
41a3888da7
@ -2603,18 +2603,19 @@ fn check_fn(&@crate_ctxt ccx, &ast::fn_decl decl, ast::proto proto,
|
||||
case (_) { }
|
||||
}
|
||||
|
||||
auto success = writeback::resolve_type_vars_in_block(fcx, body);
|
||||
|
||||
if (success && option::is_some(body.node.expr)) {
|
||||
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)) {
|
||||
auto nil = ty::mk_nil(fcx.ccx.tcx);
|
||||
if (!are_compatible(fcx, nil, tail_expr_ty)) {
|
||||
demand::simple(fcx, tail_expr.span,
|
||||
fcx.ret_ty, tail_expr_ty);
|
||||
}
|
||||
}
|
||||
|
||||
writeback::resolve_type_vars_in_block(fcx, body);
|
||||
}
|
||||
|
||||
fn check_method(&@crate_ctxt ccx, &@ast::method method) {
|
||||
|
9
src/test/run-pass/infer-fn-tail-expr.rs
Normal file
9
src/test/run-pass/infer-fn-tail-expr.rs
Normal file
@ -0,0 +1,9 @@
|
||||
// xfail-stage0
|
||||
// issue #680
|
||||
|
||||
fn f() -> int[] {
|
||||
~[]
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
Loading…
Reference in New Issue
Block a user