@@ -2216,23 +2216,24 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
2216
2216
2217
2217
check_expr( fcx, idx) ;
2218
2218
auto idx_t = expr_ty( fcx. ccx. tcx, idx) ;
2219
+ if ( !type_is_integral( fcx, idx. span, idx_t) ) {
2220
+ fcx. ccx. tcx. sess. span_err( idx. span,
2221
+ "mismatched types: expected integer but found " +
2222
+ ty_to_str( fcx. ccx. tcx, idx_t) ) ;
2223
+ }
2224
+
2219
2225
alt ( structure_of( fcx, expr. span, base_t) ) {
2220
2226
case ( ty:: ty_vec( ?mt) ) {
2221
- if ( ! type_is_integral( fcx, idx. span, idx_t) ) {
2222
- fcx. ccx. tcx. sess. span_err
2223
- ( idx. span,
2224
- "non-integral type of vec index: "
2225
- + ty_to_str( fcx. ccx. tcx, idx_t) ) ;
2226
- }
2227
+ write:: ty_only_fixup( fcx, a. id, mt. ty) ;
2228
+ }
2229
+ case ( ty:: ty_ivec( ?mt) ) {
2227
2230
write:: ty_only_fixup( fcx, a. id, mt. ty) ;
2228
2231
}
2229
2232
case ( ty:: ty_str) {
2230
- if ( ! type_is_integral( fcx, idx. span, idx_t) ) {
2231
- fcx. ccx. tcx. sess. span_err
2232
- ( idx. span,
2233
- "non-integral type of str index: "
2234
- + ty_to_str( fcx. ccx. tcx, idx_t) ) ;
2235
- }
2233
+ auto typ = ty:: mk_mach( fcx. ccx. tcx, common:: ty_u8) ;
2234
+ write:: ty_only_fixup( fcx, a. id, typ) ;
2235
+ }
2236
+ case ( ty:: ty_istr) {
2236
2237
auto typ = ty:: mk_mach( fcx. ccx. tcx, common:: ty_u8) ;
2237
2238
write:: ty_only_fixup( fcx, a. id, typ) ;
2238
2239
}
0 commit comments