mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-18 01:44:04 +00:00
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.
This commit is contained in:
parent
59a0e98096
commit
4f892dd9d7
@ -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)
|
fn identity_fold_expr_assert[ENV](&ENV e, &span sp, @expr x, ann a)
|
||||||
-> @expr {
|
-> @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 {
|
fn identity_fold_expr_port[ENV](&ENV e, &span sp, ann a) -> @expr {
|
||||||
|
@ -9,6 +9,8 @@ import util.common;
|
|||||||
import util.common.span;
|
import util.common.span;
|
||||||
import util.common.plain_ann;
|
import util.common.plain_ann;
|
||||||
|
|
||||||
|
import util.common.log_expr_err;
|
||||||
|
|
||||||
import middle.ty;
|
import middle.ty;
|
||||||
import middle.ty.ann_to_type;
|
import middle.ty.ann_to_type;
|
||||||
import middle.ty.arg;
|
import middle.ty.arg;
|
||||||
@ -1955,16 +1957,25 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case (ast.expr_check(?e, _)) {
|
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);
|
auto expr_t = check_expr(fcx, e);
|
||||||
Demand.simple(fcx, expr.span, ty.mk_bool(fcx.ccx.tcx),
|
Demand.simple(fcx, expr.span, ty.mk_bool(fcx.ccx.tcx),
|
||||||
expr_ty(fcx.ccx.tcx, expr_t));
|
expr_ty(fcx.ccx.tcx, expr_t));
|
||||||
ret @fold.respan[ast.expr_]
|
/* e must be a call expr where all arguments are either
|
||||||
(expr.span, ast.expr_check(expr_t,
|
literals or slots */
|
||||||
plain_ann(fcx.ccx.tcx)));
|
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, _)) {
|
case (ast.expr_assert(?e, _)) {
|
||||||
|
9
src/test/compile-fail/not-a-pred-2.rs
Normal file
9
src/test/compile-fail/not-a-pred-2.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// -*- rust -*-
|
||||||
|
// xfail-boot
|
||||||
|
|
||||||
|
// error-pattern: non-predicate
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
check (1 == 2); // should fail to typecheck, as (a == b)
|
||||||
|
// is not a manifest call
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user