typeck: Fix for #932

This commit is contained in:
Stefan Plantikow 2011-12-05 01:23:10 +01:00
parent f1eb7ce013
commit a69eab16ec
3 changed files with 18 additions and 0 deletions

View File

@ -2116,6 +2116,20 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
let t_1 = ast_ty_to_ty_crate(fcx.ccx, t);
let t_e = expr_ty(tcx, e);
if ty::type_is_nil(tcx, t_e) {
tcx.sess.span_err(expr.span,
"cast from nil: " +
ty_to_str(tcx, expr_ty(tcx, e)) + " as " +
ty_to_str(tcx, t_1));
}
if ty::type_is_nil(tcx, t_1) {
tcx.sess.span_err(expr.span,
"cast to nil: " +
ty_to_str(tcx, expr_ty(tcx, e)) + " as " +
ty_to_str(tcx, t_1));
}
// FIXME there are more forms of cast to support, eventually.
if !( type_is_scalar(fcx, expr.span, t_e)
&& type_is_scalar(fcx, expr.span, t_1)) {

View File

@ -0,0 +1,2 @@
// error-pattern: cast from nil: () as u32
fn main() { let u = (assert true) as u32; }

View File

@ -0,0 +1,2 @@
// error-pattern: cast to nil: u32 as ()
fn main() { let u = 0u32 as (); }