Skip to content

Commit 0db4a83

Browse files
committed
---
yaml --- r: 959 b: refs/heads/master c: 5678f5a h: refs/heads/master i: 957: f620240 955: 9096f3a 951: 547aa3e 943: b5b96f1 927: 30367b5 895: cae81d4 v: v3
1 parent c416475 commit 0db4a83

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 092af6fb764207693a01bb37ce4e38ddb8010e1e
2+
refs/heads/master: 5678f5aa567ae0ddf316caa90124c895f9730c62

trunk/src/comp/middle/typeck.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,28 @@ fn last_expr_of_block(&ast.block bloc) -> option.t[@ast.expr] {
402402
}
403403
}
404404

405+
406+
fn field_num(session.session sess, &span sp, &ast.ident id) -> uint {
407+
let uint accum = 0u;
408+
let uint i = 0u;
409+
for (u8 c in id) {
410+
if (i == 0u) {
411+
if (c != '_' as u8) {
412+
sess.span_err(sp, "bad numeric field on tuple");
413+
}
414+
} else {
415+
i += 1u;
416+
if (('0' as u8) <= c && c <= ('9' as u8)) {
417+
accum *= 10u;
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+
405427
// Type utilities
406428

407429
// FIXME: remove me when == works on these tags.
@@ -792,7 +814,6 @@ fn unify(&fn_ctxt fcx, @ty expected, @ty actual) -> unify_result {
792814
auto result = unify_step(fcx, bindings, expected_ty, actual);
793815
alt (result) {
794816
case (ures_ok(?result_ty)) {
795-
796817
fcx.locals.insert(expected_id, result_ty);
797818
}
798819
case (_) { /* empty */ }
@@ -1215,7 +1236,33 @@ fn check_expr(&fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
12151236
ast.expr_tup(args_1, ann));
12161237
}
12171238

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+
12181264
case (_) {
1265+
fcx.ccx.sess.unimpl("expr type in typeck.check_expr");
12191266
// TODO
12201267
ret expr;
12211268
}

0 commit comments

Comments
 (0)