diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2011-05-26 20:14:00 -0700 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2011-05-26 20:50:25 -0700 |
| commit | 1a96e79fe0a0d30bddd2cda1793cfa5907fa6c1d (patch) | |
| tree | f603a455f8e905ce7244b20f37bab44bff1a0aea /src/comp | |
| parent | af6b4821c163e5ad22868a270541dc0b7a04534f (diff) | |
| download | rust-1a96e79fe0a0d30bddd2cda1793cfa5907fa6c1d.tar.gz rust-1a96e79fe0a0d30bddd2cda1793cfa5907fa6c1d.zip | |
Make _|_ unify with anything
The typechecker had a number of special cases for unifying types with _|_ (as with checking if and alt). But, a value of type _|_ should be usable in any context, as such a value always diverges, and will never be used by its immediate context. Changed unify accordingly, removed special cases.
Diffstat (limited to 'src/comp')
| -rw-r--r-- | src/comp/middle/ty.rs | 6 | ||||
| -rw-r--r-- | src/comp/middle/typeck.rs | 15 |
2 files changed, 9 insertions, 12 deletions
diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index 8e1e5e82c31..56f8ca66c2f 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -2209,6 +2209,12 @@ mod unify { if (eq_ty(expected, actual)) { ret ures_ok(expected); } alt (struct(cx.tcx, actual)) { + + // a _|_ type can be used anywhere + case (ty::ty_bot) { + ret ures_ok(expected); + } + // If the RHS is a variable type, then just do the appropriate // binding. case (ty::ty_var(?actual_id)) { diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index df030d72ce8..47585b4bb73 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -1341,17 +1341,13 @@ mod pushdown { ann_to_type(scx.fcx.ccx.tcx.node_types, ann), adk); auto then_t = ty::block_ty(scx.fcx.ccx.tcx, then_0); - if (!ty::type_is_bot(scx.fcx.ccx.tcx, then_t)) { - pushdown_block(scx, expected, then_0); - } + pushdown_block(scx, expected, then_0); alt (else_0) { case (none[@ast::expr]) { /* no-op */ } case (some[@ast::expr](?e_0)) { auto else_t = ty::expr_ty(scx.fcx.ccx.tcx, e_0); - if (!ty::type_is_bot(scx.fcx.ccx.tcx, else_t)) { - pushdown_expr(scx, expected, e_0); - } + pushdown_expr(scx, expected, e_0); } } write::ty_only_fixup(scx, ann.id, t); @@ -1472,10 +1468,7 @@ mod pushdown { for (ast::arm arm_0 in arms_0) { pushdown_block(scx, expected, arm_0.block); auto bty = block_ty(scx.fcx.ccx.tcx, arm_0.block); - // Failing alt arms don't need to have a matching type - if (!ty::type_is_bot(scx.fcx.ccx.tcx, bty)) { - t = demand::simple(scx, e.span, t, bty); - } + t = demand::simple(scx, e.span, t, bty); } write::ty_only_fixup(scx, ann.id, t); } @@ -2245,8 +2238,6 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { pushdown::pushdown_expr(scx, pattern_ty, expr); - // FIXME: If all the the arms were ty_bot then the result should - // also be ty_bot. At the moment this doesn't seem to matter write::ty_only_fixup(scx, a.id, result_ty); } |
