Skip to content

Commit bc62b17

Browse files
committed
Ensure that the declared type and actual type of a constant agree
Closes #899
1 parent be5537e commit bc62b17

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/comp/middle/typeck.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,6 +2479,9 @@ fn check_const(ccx: @crate_ctxt, _sp: span, e: @ast::expr, id: ast::node_id) {
24792479
mutable fixups: fixups,
24802480
ccx: ccx};
24812481
check_expr(fcx, e);
2482+
let cty = expr_ty(fcx.ccx.tcx, e);
2483+
let declty = fcx.ccx.tcx.tcache.get(local_def(id)).ty;
2484+
demand::simple(fcx, e.span, declty, cty);
24822485
}
24832486

24842487
// A generic function for checking the pred in a check
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// error-pattern:expected str but found int
2+
3+
const i: str = 10;
4+
fn main() { log i; }

0 commit comments

Comments
 (0)