Make non-str fail expression a type checking failure instead of a translation one.
This commit is contained in:
parent
b110bbf886
commit
a2775a5b72
3 changed files with 24 additions and 4 deletions
|
@ -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)]);
|
||||
ret trans_fail_value(bcx, sp_opt, elt);
|
||||
} else {
|
||||
bcx.fcx.lcx.ccx.sess.span_fatal(expr.span,
|
||||
"fail called with unsupported \
|
||||
type " + ty_to_str(tcx, e_ty));
|
||||
cx.fcx.lcx.ccx.sess.span_bug(expr.span,
|
||||
"fail called with unsupported \
|
||||
type " + ty_to_str(tcx, e_ty));
|
||||
}
|
||||
}
|
||||
case (_) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
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
|
||||
// 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)) {
|
||||
alt (expr_opt) {
|
||||
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);
|
||||
}
|
||||
|
|
5
src/test/compile-fail/fail-expr.rs
Normal file
5
src/test/compile-fail/fail-expr.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
// error-pattern:mismatched types
|
||||
|
||||
fn main() {
|
||||
fail 5;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue