Skip to content

Commit 0abec86

Browse files
committed
Support istrs as fail argument. Issue #855
1 parent 4c936d7 commit 0abec86

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

src/comp/middle/trans.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -4409,12 +4409,22 @@ fn trans_fail_expr(cx: &@block_ctxt, sp_opt: &option::t<span>,
44094409
let e_ty = ty::expr_ty(tcx, expr);
44104410
bcx = expr_res.bcx;
44114411

4412-
44134412
if ty::type_is_str(tcx, e_ty) {
4414-
let elt =
4415-
GEP(bcx, expr_res.val,
4416-
[C_int(0), C_int(abi::vec_elt_data)]);
4417-
ret trans_fail_value(bcx, sp_opt, elt);
4413+
let is_istr = alt ty::struct(tcx, e_ty) {
4414+
ty::ty_istr. { true }
4415+
_ { false }
4416+
};
4417+
if !is_istr {
4418+
let elt =
4419+
GEP(bcx, expr_res.val,
4420+
[C_int(0), C_int(abi::vec_elt_data)]);
4421+
ret trans_fail_value(bcx, sp_opt, elt);
4422+
} else {
4423+
let data = ivec::get_dataptr(
4424+
bcx, expr_res.val,
4425+
type_of_or_i8(bcx, ty::mk_mach(tcx, ast::ty_u8)));
4426+
ret trans_fail_value(bcx, sp_opt, data);
4427+
}
44184428
} else {
44194429
bcx_ccx(cx).sess.span_bug(expr.span,
44204430
~"fail called with unsupported type "

src/comp/middle/typeck.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1860,7 +1860,15 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier,
18601860
bot = true;
18611861
alt expr_opt {
18621862
none. {/* do nothing */ }
1863-
some(e) { check_expr_with(fcx, e, ty::mk_str(tcx)); }
1863+
some(e) {
1864+
// FIXME: istr transitional. Should be:
1865+
// check_expr_with(fcx, e, ty::mk_str(tcx));
1866+
check_expr(fcx, e);
1867+
if !are_compatible(fcx, expr_ty(tcx, e), ty::mk_str(tcx))
1868+
&& !are_compatible(fcx, expr_ty(tcx, e), ty::mk_istr(tcx)) {
1869+
check_expr_with(fcx, e, ty::mk_str(tcx));
1870+
}
1871+
}
18641872
}
18651873
write::bot_ty(tcx, id);
18661874
}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// error-pattern:wooooo
22
// no-valgrind
3-
fn main() { let a = 1; if 1 == 1 { a = 2; } fail "woooo" + "o"; }
3+
fn main() { let a = 1; if 1 == 1 { a = 2; } fail ~"woooo" + ~"o"; }

0 commit comments

Comments
 (0)