Skip to content

Commit e8228e1

Browse files
committed
rustc: Demand that if conditions have bool type
Closes #513
1 parent a4d88da commit e8228e1

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/comp/middle/typeck.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,9 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
17121712
}
17131713
case (ast::expr_if(?cond, ?thn, ?elsopt, ?a)) {
17141714
check_expr(fcx, cond);
1715+
demand::simple(fcx, cond.span,
1716+
ty::mk_bool(fcx.ccx.tcx),
1717+
expr_ty(fcx.ccx.tcx, cond));
17151718
check_then_else(fcx, thn, elsopt, a, expr.span);
17161719
}
17171720
case (ast::expr_for(?decl, ?seq, ?body, ?a)) {

src/test/compile-fail/if-typeck.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// xfail-stage0
2+
// error-pattern:mismatched types
3+
// issue #513
4+
5+
fn f() {}
6+
7+
fn main() {
8+
// f is not a bool
9+
if (f) {
10+
}
11+
}

0 commit comments

Comments
 (0)