aboutsummaryrefslogtreecommitdiff
path: root/src/comp
diff options
context:
space:
mode:
authorTim Chevalier <[email protected]>2011-05-02 13:47:41 -0700
committerGraydon Hoare <[email protected]>2011-05-05 11:26:07 -0700
commit4f892dd9d732f215192f94b28392f26e88f0861e (patch)
tree080318c19494144be62617146984d7bb14478432 /src/comp
parentUn-XFAILed not-a-pred in stage0 (it fails correctly) (diff)
downloadrust-4f892dd9d732f215192f94b28392f26e88f0861e.tar.xz
rust-4f892dd9d732f215192f94b28392f26e88f0861e.zip
Check that the operand in a check is a call
In addition, fix bug in fold that was turning asserts into checks. More typechecking still needs to be done.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/fold.rs2
-rw-r--r--src/comp/middle/typeck.rs25
2 files changed, 19 insertions, 8 deletions
diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs
index e932fd9a..49b6290c 100644
--- a/src/comp/middle/fold.rs
+++ b/src/comp/middle/fold.rs
@@ -1396,7 +1396,7 @@ fn identity_fold_expr_check[ENV](&ENV e, &span sp, @expr x, ann a)
fn identity_fold_expr_assert[ENV](&ENV e, &span sp, @expr x, ann a)
-> @expr {
- ret @respan(sp, ast.expr_check(x, a));
+ ret @respan(sp, ast.expr_assert(x, a));
}
fn identity_fold_expr_port[ENV](&ENV e, &span sp, ann a) -> @expr {
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index ec50fd84..fd915108 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -9,6 +9,8 @@ import util.common;
import util.common.span;
import util.common.plain_ann;
+import util.common.log_expr_err;
+
import middle.ty;
import middle.ty.ann_to_type;
import middle.ty.arg;
@@ -1955,16 +1957,25 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
}
case (ast.expr_check(?e, _)) {
- /* FIXME */
- /* presumably, here is where we should check that e is
- actually a call to a predicate, where all the arguments
- are literals or slot variables? */
auto expr_t = check_expr(fcx, e);
Demand.simple(fcx, expr.span, ty.mk_bool(fcx.ccx.tcx),
expr_ty(fcx.ccx.tcx, expr_t));
- ret @fold.respan[ast.expr_]
- (expr.span, ast.expr_check(expr_t,
- plain_ann(fcx.ccx.tcx)));
+ /* e must be a call expr where all arguments are either
+ literals or slots */
+ alt (e.node) {
+ case (ast.expr_call(?operator, ?operands, _)) {
+ /* operator must be a pure function */
+ /* FIXME: need more checking */
+ ret @fold.respan[ast.expr_]
+ (expr.span, ast.expr_check(expr_t,
+ plain_ann(fcx.ccx.tcx)));
+
+ }
+ case (_) {
+ fcx.ccx.sess.span_err(expr.span,
+ "Check on non-predicate");
+ }
+ }
}
case (ast.expr_assert(?e, _)) {