@@ -1741,7 +1741,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
1741
1741
let element_ty = demand:: simple( fcx, local. span, element_ty,
1742
1742
ty:: mk_var( fcx. ccx. tcx, locid) ) ;
1743
1743
let bot = check_decl_local( fcx, local) ;
1744
- check_block ( fcx, body) ;
1744
+ check_block_no_value ( fcx, body) ;
1745
1745
// Unify type of decl with element type of the seq
1746
1746
demand:: simple( fcx, local. span,
1747
1747
ty:: node_id_to_type( fcx. ccx. tcx, local. node. id) ,
@@ -1756,22 +1756,27 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
1756
1756
fn check_then_else( fcx: @fn_ctxt, thn: ast:: blk,
1757
1757
elsopt: option:: t < @ast:: expr > , id: ast:: node_id,
1758
1758
_sp: span) -> bool {
1759
- let then_bot = check_block( fcx, thn) ;
1760
- let els_bot = false ;
1761
- let if_t =
1759
+ let ( if_t, if_bot) =
1762
1760
alt elsopt {
1763
1761
some( els) {
1762
+ let thn_bot = check_block( fcx, thn) ;
1764
1763
let thn_t = block_ty( fcx. ccx. tcx, thn) ;
1765
- els_bot = check_expr_with( fcx, els, thn_t) ;
1766
- let elsopt_t = expr_ty( fcx. ccx. tcx, els) ;
1767
- if !ty:: type_is_bot( fcx. ccx. tcx, elsopt_t) {
1768
- elsopt_t
1769
- } else { thn_t }
1764
+ let els_bot = check_expr_with( fcx, els, thn_t) ;
1765
+ let els_t = expr_ty( fcx. ccx. tcx, els) ;
1766
+ let if_t = if !ty:: type_is_bot( fcx. ccx. tcx, els_t) {
1767
+ els_t
1768
+ } else {
1769
+ thn_t
1770
+ } ;
1771
+ ( if_t, thn_bot & els_bot)
1772
+ }
1773
+ none. {
1774
+ check_block_no_value( fcx, thn) ;
1775
+ ( ty:: mk_nil( fcx. ccx. tcx) , false )
1770
1776
}
1771
- none . { ty : : mk_nil( fcx. ccx. tcx) }
1772
1777
} ;
1773
1778
write:: ty_only_fixup( fcx, id, if_t) ;
1774
- ret then_bot & els_bot ;
1779
+ ret if_bot ;
1775
1780
}
1776
1781
1777
1782
// Checks the compatibility
@@ -1993,12 +1998,12 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
1993
1998
}
1994
1999
ast:: expr_while( cond, body) {
1995
2000
bot = check_expr_with( fcx, cond, ty:: mk_bool( tcx) ) ;
1996
- check_block ( fcx, body) ;
2001
+ check_block_no_value ( fcx, body) ;
1997
2002
write:: ty_only_fixup( fcx, id, ty:: mk_nil( tcx) ) ;
1998
2003
}
1999
2004
ast:: expr_do_while( body, cond) {
2000
2005
bot = check_expr_with( fcx, cond, ty:: mk_bool( tcx) ) |
2001
- check_block ( fcx, body) ;
2006
+ check_block_no_value ( fcx, body) ;
2002
2007
write:: ty_only_fixup( fcx, id, block_ty( tcx, body) ) ;
2003
2008
}
2004
2009
ast:: expr_alt( expr, arms) {
@@ -2490,6 +2495,16 @@ fn check_stmt(fcx: @fn_ctxt, stmt: @ast::stmt) -> bool {
2490
2495
ret bot;
2491
2496
}
2492
2497
2498
+ fn check_block_no_value ( fcx : @fn_ctxt , blk : ast:: blk ) -> bool {
2499
+ let bot = check_block ( fcx, blk) ;
2500
+ if !bot {
2501
+ let blkty = ty:: node_id_to_monotype ( fcx. ccx . tcx , blk. node . id ) ;
2502
+ let nilty = ty:: mk_nil ( fcx. ccx . tcx ) ;
2503
+ demand:: simple ( fcx, blk. span , nilty, blkty) ;
2504
+ }
2505
+ ret bot;
2506
+ }
2507
+
2493
2508
fn check_block ( fcx0 : @fn_ctxt , blk : ast:: blk ) -> bool {
2494
2509
let fcx = alt blk. node . rules {
2495
2510
ast:: unchecked_blk. { @{ purity: ast :: impure_fn with * fcx0} }
0 commit comments