Skip to content

Commit 41a3888

Browse files
committed
Fix type inference of fn tail expressions. Closes #680
1 parent a38ba01 commit 41a3888

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/comp/middle/typeck.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,18 +2603,19 @@ fn check_fn(&@crate_ctxt ccx, &ast::fn_decl decl, ast::proto proto,
26032603
case (_) { }
26042604
}
26052605

2606-
auto success = writeback::resolve_type_vars_in_block(fcx, body);
2607-
2608-
if (success && option::is_some(body.node.expr)) {
2606+
if (option::is_some(body.node.expr)) {
26092607
auto tail_expr = option::get(body.node.expr);
26102608
auto tail_expr_ty = expr_ty(ccx.tcx, tail_expr);
26112609
// Have to exclude ty_nil to allow functions to end in
26122610
// while expressions, etc.
2613-
if (!ty::type_is_nil(ccx.tcx, tail_expr_ty)) {
2611+
auto nil = ty::mk_nil(fcx.ccx.tcx);
2612+
if (!are_compatible(fcx, nil, tail_expr_ty)) {
26142613
demand::simple(fcx, tail_expr.span,
26152614
fcx.ret_ty, tail_expr_ty);
26162615
}
26172616
}
2617+
2618+
writeback::resolve_type_vars_in_block(fcx, body);
26182619
}
26192620

26202621
fn check_method(&@crate_ctxt ccx, &@ast::method method) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// xfail-stage0
2+
// issue #680
3+
4+
fn f() -> int[] {
5+
~[]
6+
}
7+
8+
fn main() {
9+
}

0 commit comments

Comments
 (0)