From 6b742aec91f1c2615ab8e01ba027dfff3008a7f7 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Wed, 4 May 2011 15:24:07 -0700 Subject: Enforce in typechecker that preds return a bool as well as a test case --- src/comp/middle/typeck.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/comp') diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 4cea077f..68c12842 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -2841,6 +2841,17 @@ fn check_fn(&@crate_ctxt ccx, &ast.fn_decl decl, ast.proto proto, // TODO: Make sure the type of the block agrees with the function type. auto block_t = check_block(fcx, body); + alt (decl.purity) { + case (ast.pure_fn) { + // per the previous comment, this just checks that the declared + // type is bool, and trusts that that's the actual return type. + if (!ty.type_is_bool(ccx.tcx, fcx.ret_ty)) { + ccx.sess.span_err(body.span, "Non-boolean return type in pred"); + } + } + case (_) {} + } + auto block_wb = resolve_local_types_in_block(fcx, block_t); auto fn_t = rec(decl=decl, -- cgit v1.2.3