Ensure that the declared type and actual type of a constant agree

Closes 
This commit is contained in:
Marijn Haverbeke 2011-09-13 16:23:28 +02:00
parent be5537e95f
commit bc62b17543
2 changed files with 7 additions and 0 deletions
src
comp/middle
test/compile-fail

@ -2479,6 +2479,9 @@ fn check_const(ccx: @crate_ctxt, _sp: span, e: @ast::expr, id: ast::node_id) {
mutable fixups: fixups,
ccx: ccx};
check_expr(fcx, e);
let cty = expr_ty(fcx.ccx.tcx, e);
let declty = fcx.ccx.tcx.tcache.get(local_def(id)).ty;
demand::simple(fcx, e.span, declty, cty);
}
// A generic function for checking the pred in a check

@ -0,0 +1,4 @@
// error-pattern:expected str but found int
const i: str = 10;
fn main() { log i; }