1
Fork 0

Make non-str fail expression a type checking failure instead of a translation one.

This commit is contained in:
Josh Matthews 2011-07-03 02:33:35 -04:00 committed by Brian Anderson
parent b110bbf886
commit a2775a5b72
3 changed files with 24 additions and 4 deletions

View file

@ -6388,9 +6388,9 @@ fn trans_fail_expr(&@block_ctxt cx, &option::t[common::span] sp_opt,
[C_int(0), C_int(abi::vec_elt_data)]); [C_int(0), C_int(abi::vec_elt_data)]);
ret trans_fail_value(bcx, sp_opt, elt); ret trans_fail_value(bcx, sp_opt, elt);
} else { } else {
bcx.fcx.lcx.ccx.sess.span_fatal(expr.span, cx.fcx.lcx.ccx.sess.span_bug(expr.span,
"fail called with unsupported \ "fail called with unsupported \
type " + ty_to_str(tcx, e_ty)); type " + ty_to_str(tcx, e_ty));
} }
} }
case (_) { case (_) {

View file

@ -229,6 +229,11 @@ fn type_is_scalar(&@fn_ctxt fcx, &span sp, ty::t typ) -> bool {
ret ty::type_is_scalar(fcx.ccx.tcx, typ_s); ret ty::type_is_scalar(fcx.ccx.tcx, typ_s);
} }
fn type_is_str(&@fn_ctxt fcx, &span sp, ty::t typ) -> bool {
auto typ_s = structurally_resolved_type(fcx, sp, typ);
ret ty::type_is_str(fcx.ccx.tcx, typ_s);
}
// Parses the programmer's textual representation of a type into our internal // Parses the programmer's textual representation of a type into our internal
// notion of a type. `getter` is a function that returns the type // notion of a type. `getter` is a function that returns the type
@ -1658,7 +1663,17 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
case (ast::expr_fail(?expr_opt)) { case (ast::expr_fail(?expr_opt)) {
alt (expr_opt) { alt (expr_opt) {
case (none) { /* do nothing */ } case (none) { /* do nothing */ }
case (some(?e)) { check_expr(fcx, e); } case (some(?e)) {
check_expr(fcx, e);
auto tcx = fcx.ccx.tcx;
auto ety = expr_ty(tcx, e);
if (!type_is_str(fcx, e.span, ety)) {
tcx.sess.span_fatal(e.span,
#fmt("mismatched types: expected \
str, found %s",
ty_to_str(tcx, ety)));
}
}
} }
write::bot_ty(fcx.ccx.tcx, id); write::bot_ty(fcx.ccx.tcx, id);
} }

View file

@ -0,0 +1,5 @@
// error-pattern:mismatched types
fn main() {
fail 5;
}