@@ -128,6 +128,37 @@ fn substitute_ty_params(&@crate_ctxt ccx,
128
128
ret ty. fold_ty ( substituter, typ) ;
129
129
}
130
130
131
+ // Returns the type parameters and polytype of an item, if it's an item that
132
+ // supports type parameters.
133
+ fn ty_params_for_item ( @crate_ctxt ccx , & ast . def d)
134
+ -> option. t[ ty. ty_params_and_ty ] {
135
+ auto params_id;
136
+ auto types_id;
137
+ alt ( d) {
138
+ case ( ast. def_fn ( ?id) ) { params_id = id; types_id = id; }
139
+ case ( ast. def_obj ( ?id) ) { params_id = id; types_id = id; }
140
+ case ( ast. def_obj_field ( _) ) { ret none[ ty. ty_params_and_ty ] ; }
141
+ case ( ast. def_mod ( _) ) { ret none[ ty. ty_params_and_ty ] ; }
142
+ case ( ast. def_const ( _) ) { ret none[ ty. ty_params_and_ty ] ; }
143
+ case ( ast. def_arg ( _) ) { ret none[ ty. ty_params_and_ty ] ; }
144
+ case ( ast. def_local ( _) ) { ret none[ ty. ty_params_and_ty ] ; }
145
+ case ( ast. def_variant ( ?tid, ?vid) ) {
146
+ params_id = tid;
147
+ types_id = vid;
148
+ }
149
+ case ( ast. def_ty ( _) ) { ret none[ ty. ty_params_and_ty ] ; }
150
+ case ( ast. def_ty_arg ( _) ) { ret none[ ty. ty_params_and_ty ] ; }
151
+ case ( ast. def_binding ( _) ) { ret none[ ty. ty_params_and_ty ] ; }
152
+ case ( ast. def_use ( _) ) { ret none[ ty. ty_params_and_ty ] ; }
153
+ case ( ast. def_native_ty ( _) ) { ret none[ ty. ty_params_and_ty ] ; }
154
+ case ( ast. def_native_fn ( ?id) ) { params_id = id; types_id = id; }
155
+ }
156
+
157
+ auto tps = ccx. item_ty_params . get ( params_id) ;
158
+ auto polyty = ccx. item_types . get ( types_id) ;
159
+ ret some[ ty. ty_params_and_ty ] ( tup ( tps, polyty) ) ;
160
+ }
161
+
131
162
// Parses the programmer's textual representation of a type into our internal
132
163
// notion of a type. `getter` is a function that returns the type
133
164
// corresponding to a definition ID.
@@ -1190,7 +1221,38 @@ fn demand_expr_full(&@fn_ctxt fcx, @ty.t expected, @ast.expr e,
1190
1221
case ( ast. expr_path( ?pth, ?d, ?ann) ) {
1191
1222
auto t = demand_full( fcx, e. span, expected,
1192
1223
ann_to_type( ann) , adk) ;
1193
- e_1 = ast. expr_path( pth, d, ast. ann_type( t, none[ vec[ @ty. t] ] ) ) ;
1224
+
1225
+ // Fill in the type parameter substitutions if they weren't
1226
+ // provided by the programmer.
1227
+ auto ty_params_opt;
1228
+ alt ( ann) {
1229
+ case ( ast. ann_none) {
1230
+ log "demand_expr( ) : no type annotation for path expr; " +
1231
+ "did you pass it to check_expr( ) first?";
1232
+ fail;
1233
+ }
1234
+ case ( ast. ann_type( _, ?tps_opt) ) {
1235
+ alt ( tps_opt) {
1236
+ case ( none[ vec[ @ty. t] ] ) {
1237
+ auto defn = option. get[ ast. def] ( d) ;
1238
+ alt ( ty_params_for_item( fcx. ccx, defn) ) {
1239
+ case ( none[ ty. ty_params_and_ty] ) {
1240
+ ty_params_opt = none[ vec[ @ty. t] ] ;
1241
+ }
1242
+ case ( some[ ty. ty_params_and_ty] ( ?tpt) ) {
1243
+ auto tps = ty. resolve_ty_params( tpt, t) ;
1244
+ ty_params_opt = some[ vec[ @ty. t] ] ( tps) ;
1245
+ }
1246
+ }
1247
+ }
1248
+ case ( some[ vec[ @ty. t] ] ( ?tps) ) {
1249
+ ty_params_opt = some[ vec[ @ty. t] ] ( tps) ;
1250
+ }
1251
+ }
1252
+ }
1253
+ }
1254
+
1255
+ e_1 = ast. expr_path( pth, d, ast. ann_type( t, ty_params_opt) ) ;
1194
1256
}
1195
1257
case ( ast. expr_ext( ?p, ?args, ?body, ?expanded, ?ann) ) {
1196
1258
auto t = demand_full( fcx, e. span, expected,
0 commit comments