@@ -402,6 +402,28 @@ fn last_expr_of_block(&ast.block bloc) -> option.t[@ast.expr] {
402
402
}
403
403
}
404
404
405
+
406
+ fn field_num ( session . session sess, & span sp, & ast . ident id) -> uint {
407
+ let uint accum = 0 u;
408
+ let uint i = 0 u;
409
+ for ( u8 c in id) {
410
+ if ( i == 0 u) {
411
+ if ( c != '_' as u8 ) {
412
+ sess. span_err ( sp, "bad numeric field on tuple" ) ;
413
+ }
414
+ } else {
415
+ i += 1 u;
416
+ if ( ( '0' as u8 ) <= c && c <= ( '9' as u8 ) ) {
417
+ accum *= 10 u;
418
+ accum += ( c as uint ) - ( '0' as uint ) ;
419
+ } else {
420
+ sess. span_err ( sp, "bad numeric field on tuple" ) ;
421
+ }
422
+ }
423
+ }
424
+ ret accum;
425
+ }
426
+
405
427
// Type utilities
406
428
407
429
// FIXME: remove me when == works on these tags.
@@ -792,7 +814,6 @@ fn unify(&fn_ctxt fcx, @ty expected, @ty actual) -> unify_result {
792
814
auto result = unify_step ( fcx, bindings, expected_ty, actual) ;
793
815
alt ( result) {
794
816
case ( ures_ok ( ?result_ty) ) {
795
-
796
817
fcx. locals . insert ( expected_id, result_ty) ;
797
818
}
798
819
case ( _) { /* empty */ }
@@ -1215,7 +1236,33 @@ fn check_expr(&fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
1215
1236
ast. expr_tup ( args_1, ann) ) ;
1216
1237
}
1217
1238
1239
+ case ( ast. expr_field ( ?base, ?field, _) ) {
1240
+ auto base_1 = check_expr ( fcx, base) ;
1241
+ auto base_t = expr_ty ( base_1) ;
1242
+ alt ( base_t. struct ) {
1243
+ case ( ty_tup( ?args) ) {
1244
+ let uint ix = field_num ( fcx. ccx . sess ,
1245
+ expr. span , field) ;
1246
+ if ( ix >= _vec. len [ tup ( bool, @ty) ] ( args) ) {
1247
+ fcx. ccx . sess . span_err ( expr. span ,
1248
+ "bad index on tuple" ) ;
1249
+ }
1250
+ auto ann = ast. ann_type ( args. ( ix) . _1 ) ;
1251
+ ret @fold. respan [ ast. expr_ ] ( expr. span ,
1252
+ ast. expr_field ( base_1,
1253
+ field,
1254
+ ann) ) ;
1255
+ }
1256
+ case ( _) {
1257
+ fcx. ccx . sess . unimpl ( "base type for expr_field "
1258
+ + "in typeck.check_expr: "
1259
+ + ty_to_str ( base_t) ) ;
1260
+ }
1261
+ }
1262
+ }
1263
+
1218
1264
case ( _) {
1265
+ fcx. ccx . sess . unimpl ( "expr type in typeck.check_expr" ) ;
1219
1266
// TODO
1220
1267
ret expr;
1221
1268
}
0 commit comments