Properly typecheck unary minus

Closes #813
This commit is contained in:
Marijn Haverbeke 2011-08-12 16:05:56 +02:00
parent e8d170beae
commit de4b383a0f
2 changed files with 14 additions and 1 deletions

View file

@ -1842,7 +1842,15 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr,
ty_to_str(tcx, oper_t))); ty_to_str(tcx, oper_t)));
} }
} }
_ { oper_t = do_autoderef(fcx, expr.span, oper_t); } ast::neg. {
oper_t = structurally_resolved_type
(fcx, oper.span, do_autoderef(fcx, expr.span, oper_t));
if !(ty::type_is_integral(tcx, oper_t) ||
ty::type_is_fp(tcx, oper_t)) {
tcx.sess.span_fatal(expr.span, "applying unary minus to \
non-numeric type " + ty_to_str(tcx, oper_t));
}
}
} }
write::ty_only_fixup(fcx, id, oper_t); write::ty_only_fixup(fcx, id, oper_t);
} }

View file

@ -0,0 +1,5 @@
// error-pattern:applying unary minus to non-numeric type str
fn main() {
-"foo";
}