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 +++++++++++ src/test/compile-fail/pred-not-bool.rs | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'src') 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, diff --git a/src/test/compile-fail/pred-not-bool.rs b/src/test/compile-fail/pred-not-bool.rs index c0d19ef2..7c7fa3d1 100644 --- a/src/test/compile-fail/pred-not-bool.rs +++ b/src/test/compile-fail/pred-not-bool.rs @@ -1,6 +1,8 @@ // -*- rust -*- +// xfail-boot +// xfail-stage0 -// error-pattern: mismatched types +// error-pattern: Non-boolean return type // this checks that a pred with a non-bool return // type is rejected, even if the pred is never used -- cgit v1.2.3