rustc: Allow alt expressions to fail

This commit is contained in:
Brian Anderson 2011-05-13 14:42:23 -04:00
parent 418b4c4567
commit 6824f119fc
3 changed files with 52 additions and 3 deletions

View File

@ -1457,7 +1457,10 @@ 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);
t = Demand::simple(scx, e.span, t, bty);
// 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);
}
}
write::ty_only_fixup(scx, ann.id, t);
}
@ -2209,8 +2212,11 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) {
check_block(scx, arm.block);
auto bty = block_ty(scx.fcx.ccx.tcx, arm.block);
result_ty = Demand::simple(scx, arm.block.span, result_ty,
bty);
// Failing alt arms don't need to have a matching type
if (!ty::type_is_bot(scx.fcx.ccx.tcx, bty)) {
result_ty = Demand::simple(scx, arm.block.span,
result_ty, bty);
}
}
auto i = 0u;

View File

@ -0,0 +1,13 @@
// xfail-stage0
// error-pattern:explicit failure
fn main() {
auto x = alt(true) {
case (false) {
0
}
case (true) {
fail
}
};
}

View File

@ -0,0 +1,30 @@
// xfail-stage0
fn test_simple() {
auto r = alt (true) {
case (true) {
true
}
case (false) {
fail
}
};
assert (r == true);
}
fn test_box() {
auto r = alt (true) {
case (true) {
[10]
}
case (false) {
fail
}
};
assert (r.(0) == 10);
}
fn main() {
test_simple();
test_box();
}