Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure fail expression is walked, and make fail with a non-string expression fail typechecking. #617

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/comp/middle/trans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6375,9 +6375,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(cx, sp_opt, elt);
} else {
cx.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 (_) {
Expand Down
7 changes: 6 additions & 1 deletion src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,12 @@ 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);
demand::simple(fcx, e.span, ty::mk_str(tcx), ety);
}
}
write::bot_ty(fcx.ccx.tcx, id);
}
Expand Down
2 changes: 1 addition & 1 deletion src/comp/middle/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ fn visit_expr[E](&@expr ex, &E e, &vt[E] v) {
case (expr_ext(_, _, _, ?expansion)) {
vt(v).visit_expr(expansion, e, v);
}
case (expr_fail(_)) { }
case (expr_fail(?eo)) { visit_expr_opt(eo, e, v); }
case (expr_break) { }
case (expr_cont) { }
case (expr_ret(?eo)) { visit_expr_opt(eo, e, v); }
Expand Down
5 changes: 5 additions & 0 deletions src/test/compile-fail/fail-expr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// error-pattern:mismatched types

fn main() {
fail 5;
}