rustc: Typecheck whiles and do-whiles. Add a workaround to complex.rs pending a solution to the one-armed-if problem.

This commit is contained in:
Patrick Walton 2010-11-23 17:02:08 -08:00
parent 4208352527
commit f55f46af64
3 changed files with 24 additions and 1 deletions

View File

@ -545,6 +545,7 @@ TEST_XFAILS_SELF := $(filter-out \
$(addprefix test/compile-fail/, \
arg-count-mismatch.rs \
arg-type-mismatch.rs \
while-type-error.rs \
), \
$(wildcard test/*/*.rs test/*/*.rc))

View File

@ -1073,6 +1073,27 @@ fn check_expr(&fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
ast.ann_type(elsopt_t)));
}
case (ast.expr_while(?cond, ?body, _)) {
auto cond_0 = check_expr(fcx, cond);
auto cond_1 = demand_expr(fcx, plain_ty(ty_bool), cond_0);
auto body_1 = check_block(fcx, body);
auto ann = ast.ann_type(plain_ty(ty_nil));
ret @fold.respan[ast.expr_](expr.span,
ast.expr_while(cond_1, body_1, ann));
}
case (ast.expr_do_while(?body, ?cond, _)) {
auto cond_0 = check_expr(fcx, cond);
auto cond_1 = demand_expr(fcx, plain_ty(ty_bool), cond_0);
auto body_1 = check_block(fcx, body);
auto ann = ast.ann_type(block_ty(body_1));
ret @fold.respan[ast.expr_](expr.span,
ast.expr_do_while(body_1, cond_1,
ann));
}
case (ast.expr_call(?f, ?args, _)) {
// Check the function.
auto f_0 = check_expr(fcx, f);

View File

@ -1,6 +1,7 @@
// -*- rust -*-
type t = int;
fn nothing() {}
fn putstr(str s) {}
fn putint(int i) {
let int i = 33;
@ -15,7 +16,7 @@ fn foo(int x) -> int {
while (y < 10) {
putint(y);
if (y * 3 == 4) {
y = y + 2;
y = y + 2; nothing();
}
}
let t z;