Skip to content

Commit

Permalink
rustc: Demand that if conditions have bool type
Browse files Browse the repository at this point in the history
Closes #513
  • Loading branch information
brson committed Jun 17, 2011
1 parent a4d88da commit e8228e1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,9 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
}
case (ast::expr_if(?cond, ?thn, ?elsopt, ?a)) {
check_expr(fcx, cond);
demand::simple(fcx, cond.span,
ty::mk_bool(fcx.ccx.tcx),
expr_ty(fcx.ccx.tcx, cond));
check_then_else(fcx, thn, elsopt, a, expr.span);
}
case (ast::expr_for(?decl, ?seq, ?body, ?a)) {
Expand Down
11 changes: 11 additions & 0 deletions src/test/compile-fail/if-typeck.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// xfail-stage0
// error-pattern:mismatched types
// issue #513

fn f() {}

fn main() {
// f is not a bool
if (f) {
}
}

0 comments on commit e8228e1

Please sign in to comment.