Support istrs as fail argument. Issue #855

This commit is contained in:
Brian Anderson 2011-08-27 23:06:17 -07:00 committed by Brian Anderson
parent 4c936d7992
commit 0abec867c3
3 changed files with 25 additions and 7 deletions

View file

@ -4409,12 +4409,22 @@ fn trans_fail_expr(cx: &@block_ctxt, sp_opt: &option::t<span>,
let e_ty = ty::expr_ty(tcx, expr);
bcx = expr_res.bcx;
if ty::type_is_str(tcx, e_ty) {
let elt =
GEP(bcx, expr_res.val,
[C_int(0), C_int(abi::vec_elt_data)]);
ret trans_fail_value(bcx, sp_opt, elt);
let is_istr = alt ty::struct(tcx, e_ty) {
ty::ty_istr. { true }
_ { false }
};
if !is_istr {
let elt =
GEP(bcx, expr_res.val,
[C_int(0), C_int(abi::vec_elt_data)]);
ret trans_fail_value(bcx, sp_opt, elt);
} else {
let data = ivec::get_dataptr(
bcx, expr_res.val,
type_of_or_i8(bcx, ty::mk_mach(tcx, ast::ty_u8)));
ret trans_fail_value(bcx, sp_opt, data);
}
} else {
bcx_ccx(cx).sess.span_bug(expr.span,
~"fail called with unsupported type "

View file

@ -1860,7 +1860,15 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier,
bot = true;
alt expr_opt {
none. {/* do nothing */ }
some(e) { check_expr_with(fcx, e, ty::mk_str(tcx)); }
some(e) {
// FIXME: istr transitional. Should be:
// check_expr_with(fcx, e, ty::mk_str(tcx));
check_expr(fcx, e);
if !are_compatible(fcx, expr_ty(tcx, e), ty::mk_str(tcx))
&& !are_compatible(fcx, expr_ty(tcx, e), ty::mk_istr(tcx)) {
check_expr_with(fcx, e, ty::mk_str(tcx));
}
}
}
write::bot_ty(tcx, id);
}

View file

@ -1,3 +1,3 @@
// error-pattern:wooooo
// no-valgrind
fn main() { let a = 1; if 1 == 1 { a = 2; } fail "woooo" + "o"; }
fn main() { let a = 1; if 1 == 1 { a = 2; } fail ~"woooo" + ~"o"; }