@@ -98,6 +98,24 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty.t {
98
98
ret ty. fold_ty ( replacer, t) ;
99
99
}
100
100
101
+ fn instantiate ( ty_getter getter, ast. def_id id ,
102
+ vec[ @ast. ty] args) -> @ty. t {
103
+ // TODO: maybe record cname chains so we can do
104
+ // "foo = int" like OCaml?
105
+ auto ty_and_params = getter ( id) ;
106
+ auto params = ty_and_params. params ;
107
+ auto num_type_args = _vec. len [ @ast. ty ] ( args) ;
108
+ check ( num_type_args == _vec. len [ ast. ty_param ] ( params) ) ;
109
+
110
+ auto param_map = common. new_def_hash [ @ty. t] ( ) ;
111
+ for each ( uint i in _uint. range( 0 u, num_type_args) ) {
112
+ auto arg = args. ( i) ;
113
+ auto param = params. ( i) ;
114
+ param_map. insert( param. id, ast_ty_to_ty( getter, arg) ) ;
115
+ }
116
+ ret replace_type_params( ty_and_params. ty, param_map) ;
117
+ }
118
+
101
119
auto mut = ast. imm;
102
120
auto sty;
103
121
auto cname = none[ str] ;
@@ -137,22 +155,10 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty.t {
137
155
check ( def ! = none[ ast. def] ) ;
138
156
alt ( option. get[ ast. def] ( def) ) {
139
157
case ( ast. def_ty( ?id) ) {
140
- // TODO: maybe record cname chains so we can do
141
- // "foo = int" like OCaml?
142
- auto ty_and_params = getter ( id) ;
143
- auto params = ty_and_params. params ;
144
- auto num_type_params = _vec. len [ @ast. ty ] ( path. node . types ) ;
145
- check ( num_type_params == _vec. len [ ast. ty_param ] ( params) ) ;
146
-
147
- auto param_map = common. new_def_hash [ @ty. t] ( ) ;
148
- for each ( uint i in _uint. range( 0 u, num_type_params) ) {
149
- auto x = path. node. types. ( i) ;
150
- auto y = params. ( i) ;
151
- param_map. insert( y. id, ast_ty_to_ty( getter, x) ) ;
152
- }
153
-
154
- sty = replace_type_params( ty_and_params. ty,
155
- param_map) . struct ;
158
+ sty = instantiate( getter, id, path. node. types) . struct ;
159
+ }
160
+ case ( ast. def_obj( ?id) ) {
161
+ sty = instantiate( getter, id, path. node. types) . struct ;
156
162
}
157
163
case ( ast. def_ty_arg( ?id) ) { sty = ty. ty_param( id) ; }
158
164
case ( _) { fail; }
@@ -190,11 +196,21 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty.t {
190
196
// ast_ty_to_ty.
191
197
fn ast_ty_to_ty_crate( @crate_ctxt ccx, & @ast. ty ast_ty) -> @ty. t {
192
198
fn getter( @crate_ctxt ccx, ast. def_id id) -> ty_and_params {
193
- check ( ccx. item_types. contains_key( id) ) ;
194
199
check ( ccx. item_items. contains_key( id) ) ;
195
- auto ty = ccx. item_types. get ( id) ;
200
+ check ( ccx. item_types. contains_key ( id) ) ;
196
201
auto item = ccx. item_items. get( id) ;
202
+ auto ty = ccx. item_types. get( id) ;
197
203
auto params = ty_params_of_item( item) ;
204
+
205
+ alt ( item. node) {
206
+ case ( ast. item_obj( _, _, _, _, _) ) {
207
+ // An obj used as a type name refers to the output type of the
208
+ // item (constructor).
209
+ ty = middle. ty. ty_fn_ret( ty) ;
210
+ }
211
+ case ( _) { }
212
+ }
213
+
198
214
ret rec( params = params, ty = ty) ;
199
215
}
200
216
auto f = bind getter( ccx, _) ;
@@ -243,6 +259,16 @@ fn collect_item_types(session.session sess, @ast.crate crate)
243
259
auto item = id_to_ty_item. get( id) ;
244
260
auto ty = ty_of_item( id_to_ty_item, item_to_ty, item) ;
245
261
auto params = ty_params_of_item( item) ;
262
+
263
+ alt ( item. node) {
264
+ case ( ast. item_obj( _, _, _, _, _) ) {
265
+ // An obj used as a type name refers to the output type of the
266
+ // item (constructor).
267
+ ty = middle. ty. ty_fn_ret( ty) ;
268
+ }
269
+ case ( _) { }
270
+ }
271
+
246
272
ret rec( params = params, ty = ty) ;
247
273
}
248
274
@@ -400,6 +426,9 @@ fn collect_item_types(session.session sess, @ast.crate crate)
400
426
case ( ast. item_tag( _, _, _, ?def_id) ) {
401
427
id_to_ty_item. insert( def_id, i) ;
402
428
}
429
+ case ( ast. item_obj( _, _, _, ?def_id, _) ) {
430
+ id_to_ty_item. insert( def_id, i) ;
431
+ }
403
432
case ( _) { /* empty */ }
404
433
}
405
434
ret id_to_ty_item;
0 commit comments