aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Walton <[email protected]>2010-11-23 17:02:08 -0800
committerPatrick Walton <[email protected]>2010-11-23 17:02:08 -0800
commitf55f46af64e545a5845a14e6157211773c24193e (patch)
treeded516265ba4ae8112bb562a9f6fcb4d5993d3c1
parentrustc: As an experiment, swap the expected/actual types when checking functio... (diff)
downloadrust-f55f46af64e545a5845a14e6157211773c24193e.tar.xz
rust-f55f46af64e545a5845a14e6157211773c24193e.zip
rustc: Typecheck whiles and do-whiles. Add a workaround to complex.rs pending a solution to the one-armed-if problem.
-rw-r--r--src/Makefile1
-rw-r--r--src/comp/middle/typeck.rs21
-rw-r--r--src/test/run-pass/complex.rs3
3 files changed, 24 insertions, 1 deletions
diff --git a/src/Makefile b/src/Makefile
index a1bbb727..0a944ec3 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -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))
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index 6a5351fa..aefb92bc 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -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);
diff --git a/src/test/run-pass/complex.rs b/src/test/run-pass/complex.rs
index 3687de7a..f65159ce 100644
--- a/src/test/run-pass/complex.rs
+++ b/src/test/run-pass/complex.rs
@@ -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;