Ensure that the declared type and actual type of a constant agree
Closes #899
This commit is contained in:
parent
be5537e95f
commit
bc62b17543
src
@ -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
|
||||
|
4
src/test/compile-fail/bad-const-type.rs
Normal file
4
src/test/compile-fail/bad-const-type.rs
Normal file
@ -0,0 +1,4 @@
|
||||
// error-pattern:expected str but found int
|
||||
|
||||
const i: str = 10;
|
||||
fn main() { log i; }
|
Loading…
x
Reference in New Issue
Block a user