about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2011-05-04 15:24:07 -0700
committerGraydon Hoare <graydon@mozilla.com>2011-05-05 11:26:07 -0700
commit6b742aec91f1c2615ab8e01ba027dfff3008a7f7 (patch)
treef3f090cec6aff94ed2c28e4d6513a224c88cc637 /src/comp
parent910a05d8758045f545aabd724aace4fadb10e9aa (diff)
downloadrust-6b742aec91f1c2615ab8e01ba027dfff3008a7f7.tar.gz
rust-6b742aec91f1c2615ab8e01ba027dfff3008a7f7.zip
Enforce in typechecker that preds return a bool
as well as a test case
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/typeck.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index 4cea077ff49..68c12842f0a 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,