Skip to content

Commit a69eab1

Browse files
committed
typeck: Fix for #932
1 parent f1eb7ce commit a69eab1

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/comp/middle/typeck.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,6 +2116,20 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
21162116
let t_1 = ast_ty_to_ty_crate(fcx.ccx, t);
21172117
let t_e = expr_ty(tcx, e);
21182118

2119+
if ty::type_is_nil(tcx, t_e) {
2120+
tcx.sess.span_err(expr.span,
2121+
"cast from nil: " +
2122+
ty_to_str(tcx, expr_ty(tcx, e)) + " as " +
2123+
ty_to_str(tcx, t_1));
2124+
}
2125+
2126+
if ty::type_is_nil(tcx, t_1) {
2127+
tcx.sess.span_err(expr.span,
2128+
"cast to nil: " +
2129+
ty_to_str(tcx, expr_ty(tcx, e)) + " as " +
2130+
ty_to_str(tcx, t_1));
2131+
}
2132+
21192133
// FIXME there are more forms of cast to support, eventually.
21202134
if !( type_is_scalar(fcx, expr.span, t_e)
21212135
&& type_is_scalar(fcx, expr.span, t_1)) {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// error-pattern: cast from nil: () as u32
2+
fn main() { let u = (assert true) as u32; }

src/test/compile-fail/cast-to-nil.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// error-pattern: cast to nil: u32 as ()
2+
fn main() { let u = 0u32 as (); }

0 commit comments

Comments
 (0)