Skip to content

Commit c7a02b8

Browse files
committed
---
yaml --- r: 1183 b: refs/heads/master c: 546f1e9 h: refs/heads/master i: 1181: 92815bd 1179: 7c61607 1175: c6fd94f 1167: fa44842 1151: 1db8c6d v: v3
1 parent f2fc0f8 commit c7a02b8

File tree

2 files changed

+58
-14
lines changed

2 files changed

+58
-14
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: 771d76e5520bb886624e4541ff3b74f2d6513bd6
2+
refs/heads/master: 546f1e98cb0da4a4f72b9f64afd0e38e6ea45c08

trunk/src/comp/middle/typeck.rs

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,10 @@ fn demand_expr(&@fn_ctxt fcx, @ty.t expected, @ast.expr e) -> @ast.expr {
672672
}
673673
e_1 = ast.expr_rec(fields_1, ast.ann_type(t));
674674
}
675+
case (ast.expr_bind(?sube, ?es, ?ann)) {
676+
auto t = demand(fcx, e.span, expected, ann_to_type(ann));
677+
e_1 = ast.expr_bind(sube, es, ast.ann_type(t));
678+
}
675679
case (ast.expr_call(?sube, ?es, ?ann)) {
676680
auto t = demand(fcx, e.span, expected, ann_to_type(ann));
677681
e_1 = ast.expr_call(sube, es, ast.ann_type(t));
@@ -1105,6 +1109,50 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
11051109
ast.expr_alt(expr_1, arms_1, ann));
11061110
}
11071111

1112+
case (ast.expr_bind(?f, ?args, _)) {
1113+
auto f_0 = check_expr(fcx, f);
1114+
auto t_0 = expr_ty(f_0);
1115+
1116+
if (!ty.is_fn_ty(t_0)) {
1117+
fcx.ccx.sess.span_err(f_0.span,
1118+
"mismatched types: bind callee has " +
1119+
"non-function type: " +
1120+
ty_to_str(t_0));
1121+
}
1122+
1123+
let vec[arg] arg_tys_0 = ty.ty_fn_args(t_0);
1124+
let @ty.t rt_0 = ty.ty_fn_ret(t_0);
1125+
let vec[option.t[@ast.expr]] args_1 = vec();
1126+
1127+
let uint i = 0u;
1128+
1129+
let vec[arg] residual_args = vec();
1130+
for (option.t[@ast.expr] a in args) {
1131+
alt (a) {
1132+
case (none[@ast.expr]) {
1133+
append[arg](residual_args,
1134+
arg_tys_0.(i));
1135+
append[option.t[@ast.expr]](args_1,
1136+
none[@ast.expr]);
1137+
}
1138+
case (some[@ast.expr](?sa)) {
1139+
auto arg_1 = check_expr(fcx, sa);
1140+
auto arg_t = expr_ty(arg_1);
1141+
demand_expr(fcx, arg_tys_0.(i).ty, arg_1);
1142+
append[option.t[@ast.expr]](args_1,
1143+
some[@ast.expr](arg_1));
1144+
}
1145+
}
1146+
i += 1u;
1147+
}
1148+
1149+
let @ty.t t_1 = plain_ty(ty.ty_fn(residual_args, rt_0));
1150+
ret @fold.respan[ast.expr_](expr.span,
1151+
ast.expr_bind(f_0, args_1,
1152+
ast.ann_type(t_1)));
1153+
1154+
}
1155+
11081156
case (ast.expr_call(?f, ?args, _)) {
11091157

11101158
// Check the function.
@@ -1128,21 +1176,17 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
11281176

11291177
// Take the argument types out of the resulting function type.
11301178
auto t_1 = expr_ty(f_1);
1131-
let vec[arg] arg_tys_1 = vec(); // TODO: typestate botch
1132-
let @ty.t rt_1 = plain_ty(ty.ty_nil); // TODO: typestate botch
1133-
alt (t_1.struct) {
1134-
case (ty.ty_fn(?arg_tys, ?rt)) {
1135-
arg_tys_1 = arg_tys;
1136-
rt_1 = rt;
1137-
}
1138-
case (_) {
1139-
fcx.ccx.sess.span_err(f_1.span,
1140-
"mismatched types: callee has " +
1141-
"non-function type: " +
1142-
ty_to_str(t_1));
1143-
}
1179+
1180+
if (!ty.is_fn_ty(t_1)) {
1181+
fcx.ccx.sess.span_err(f_1.span,
1182+
"mismatched types: callee has " +
1183+
"non-function type: " +
1184+
ty_to_str(t_1));
11441185
}
11451186

1187+
let vec[arg] arg_tys_1 = ty.ty_fn_args(t_1);
1188+
let @ty.t rt_1 = ty.ty_fn_ret(t_1);
1189+
11461190
// Unify and write back to the arguments.
11471191
auto i = 0u;
11481192
let vec[@ast.expr] args_1 = vec();

0 commit comments

Comments
 (0)