@@ -128,74 +128,77 @@ fn substitute_ty_params(&@crate_ctxt ccx,
128
128
ret ty. fold_ty ( substituter, typ) ;
129
129
}
130
130
131
- // Instantiates the given path, which must refer to an item with the given
132
- // definition.
133
- fn instantiate_path ( @fn_ctxt fcx , & ast. path pth , & ast. def defn , & span sp)
134
- -> ast . ann {
135
- auto t;
136
- auto ty_params;
131
+ type ty_params_opt_and_ty = tup ( option. t[ vec[ ast. def_id ] ] , @ty. t ) ;
132
+
133
+ // Returns the type parameters and the type for the given definition.
134
+ fn ty_params_and_ty_for_def ( @fn_ctxt fcx , & ast. def defn )
135
+ -> ty_params_opt_and_ty {
137
136
alt ( defn) {
138
137
case ( ast. def_arg ( ?id) ) {
139
138
check ( fcx. locals . contains_key ( id) ) ;
140
- t = fcx. locals . get ( id) ;
141
- ty_params = none[ vec[ ast. def_id ] ] ;
139
+ ret tup( none[ vec[ ast. def_id ] ] , fcx. locals . get ( id) ) ;
142
140
}
143
141
case ( ast. def_local ( ?id) ) {
142
+ auto t;
144
143
alt ( fcx. locals . find ( id) ) {
145
144
case ( some[ @ty. t] ( ?t1) ) { t = t1; }
146
145
case ( none[ @ty. t] ) { t = plain_ty ( ty. ty_local ( id) ) ; }
147
146
}
148
- ty_params = none[ vec[ ast. def_id ] ] ;
147
+ ret tup ( none[ vec[ ast. def_id ] ] , t ) ;
149
148
}
150
149
case ( ast. def_obj_field ( ?id) ) {
151
150
check ( fcx. locals . contains_key ( id) ) ;
152
- t = fcx. locals . get ( id) ;
153
- ty_params = none[ vec[ ast. def_id ] ] ;
151
+ ret tup( none[ vec[ ast. def_id ] ] , fcx. locals . get ( id) ) ;
154
152
}
155
153
case ( ast. def_fn ( ?id) ) {
156
154
check ( fcx. ccx . item_types . contains_key ( id) ) ;
157
- t = fcx. ccx . item_types . get ( id) ;
158
- ty_params = some ( fcx. ccx . item_ty_params . get ( id) ) ;
155
+ ret tup ( some ( fcx. ccx . item_ty_params . get ( id) ) ,
156
+ fcx. ccx . item_types . get ( id) ) ;
159
157
}
160
158
case ( ast. def_native_fn ( ?id) ) {
161
159
check ( fcx. ccx . item_types . contains_key ( id) ) ;
162
- t = fcx. ccx . item_types . get ( id) ;
163
- ty_params = some ( fcx. ccx . item_ty_params . get ( id) ) ;
160
+ ret tup ( some ( fcx. ccx . item_ty_params . get ( id) ) ,
161
+ fcx. ccx . item_types . get ( id) ) ;
164
162
}
165
163
case ( ast. def_const ( ?id) ) {
166
164
check ( fcx. ccx . item_types . contains_key ( id) ) ;
167
- t = fcx. ccx . item_types . get ( id) ;
168
- ty_params = none[ vec[ ast. def_id ] ] ;
165
+ ret tup( none[ vec[ ast. def_id ] ] , fcx. ccx . item_types . get ( id) ) ;
169
166
}
170
167
case ( ast. def_variant ( ?tag_id, ?variant_id) ) {
171
168
check ( fcx. ccx . item_types . contains_key ( variant_id) ) ;
172
- t = fcx. ccx . item_types . get ( variant_id ) ;
173
- ty_params = some ( fcx. ccx . item_ty_params . get ( tag_id ) ) ;
169
+ ret tup ( some ( fcx. ccx . item_ty_params . get ( tag_id ) ) ,
170
+ fcx. ccx . item_types . get ( variant_id ) ) ;
174
171
}
175
172
case ( ast. def_binding ( ?id) ) {
176
173
check ( fcx. locals . contains_key ( id) ) ;
177
- t = fcx. locals . get ( id) ;
178
- ty_params = none[ vec[ ast. def_id ] ] ;
174
+ ret tup( none[ vec[ ast. def_id ] ] , fcx. locals . get ( id) ) ;
179
175
}
180
176
case ( ast. def_obj ( ?id) ) {
181
177
check ( fcx. ccx . item_types . contains_key ( id) ) ;
182
- t = fcx. ccx . item_types . get ( id) ;
183
- ty_params = some ( fcx. ccx . item_ty_params . get ( id) ) ;
178
+ ret tup ( some ( fcx. ccx . item_ty_params . get ( id) ) ,
179
+ fcx. ccx . item_types . get ( id) ) ;
184
180
}
185
181
186
182
case ( ast. def_mod ( _) ) {
187
183
// Hopefully part of a path.
188
- t = plain_ty ( ty . ty_nil ) ; // TODO: something more poisonous?
189
- ty_params = none[ vec[ ast. def_id ] ] ;
184
+ // TODO: return a type that's more poisonous, perhaps ?
185
+ ret tup ( none[ vec[ ast. def_id ] ] , plain_ty ( ty . ty_nil ) ) ;
190
186
}
191
187
192
188
case ( _) {
193
189
// FIXME: handle other names.
194
- fcx. ccx . sess . unimpl ( "definition variant for: "
195
- + _str. connect ( pth. node . idents , "." ) ) ;
190
+ fcx. ccx . sess . unimpl ( "definition variant" ) ;
196
191
fail;
197
192
}
198
193
}
194
+ }
195
+
196
+ // Instantiates the given path, which must refer to an item with the given
197
+ // type parameters and type.
198
+ fn instantiate_path ( @fn_ctxt fcx , & ast. path pth , & ty_params_opt_and_ty tpt,
199
+ & span sp) -> ast . ann {
200
+ auto ty_params = tpt. _0 ;
201
+ auto t = tpt. _1 ;
199
202
200
203
auto ty_substs_opt;
201
204
auto ty_substs_len = _vec. len [ @ast. ty ] ( pth. node . types ) ;
@@ -1669,7 +1672,8 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
1669
1672
auto t = plain_ty( ty. ty_nil) ;
1670
1673
check ( defopt != none[ ast. def] ) ;
1671
1674
auto defn = option. get[ ast. def] ( defopt) ;
1672
- auto ann = instantiate_path( fcx, pth, defn, expr. span) ;
1675
+ auto tpt = ty_params_and_ty_for_def( fcx, defn) ;
1676
+ auto ann = instantiate_path( fcx, pth, tpt, expr. span) ;
1673
1677
ret @fold. respan[ ast. expr_] ( expr. span,
1674
1678
ast. expr_path( pth, defopt, ann) ) ;
1675
1679
}
0 commit comments