@@ -672,6 +672,10 @@ fn demand_expr(&@fn_ctxt fcx, @ty.t expected, @ast.expr e) -> @ast.expr {
672
672
}
673
673
e_1 = ast. expr_rec( fields_1, ast. ann_type( t) ) ;
674
674
}
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
+ }
675
679
case ( ast. expr_call( ?sube, ?es, ?ann) ) {
676
680
auto t = demand( fcx, e. span, expected, ann_to_type( ann) ) ;
677
681
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 {
1105
1109
ast. expr_alt( expr_1, arms_1, ann) ) ;
1106
1110
}
1107
1111
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 = 0 u;
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 += 1 u;
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
+
1108
1156
case ( ast. expr_call( ?f, ?args, _) ) {
1109
1157
1110
1158
// Check the function.
@@ -1128,21 +1176,17 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
1128
1176
1129
1177
// Take the argument types out of the resulting function type.
1130
1178
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) ) ;
1144
1185
}
1145
1186
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
+
1146
1190
// Unify and write back to the arguments.
1147
1191
auto i = 0 u;
1148
1192
let vec[ @ast. expr] args_1 = vec( ) ;
0 commit comments