From 41a3888da7fbcff128f03c16a8cefe4d74ab5a58 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 12 Jul 2011 16:27:22 -0700 Subject: Fix type inference of fn tail expressions. Closes #680 --- src/comp/middle/typeck.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/comp/middle') diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index b74e4950859..26351bfadec 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -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) { -- cgit 1.4.1-3-g733a5