@@ -39,6 +39,7 @@ tag sty {
39
39
ty_machine ( util. common . ty_mach ) ;
40
40
ty_char;
41
41
ty_str;
42
+ ty_tag ( ast. def_id ) ;
42
43
ty_box ( @ty) ;
43
44
ty_vec ( @ty) ;
44
45
ty_tup ( vec[ @ty] ) ;
@@ -401,6 +402,34 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) {
401
402
}
402
403
}
403
404
405
+ fn add_tag_variant_types ( @hashmap[ ast. def_id, @ast. item] id_to_ty_item ,
406
+ @ty_table item_to_ty ,
407
+ & ast. def_id tag_id ,
408
+ & vec[ ast. variant] variants ) {
409
+ for ( ast. variant variant in variants) {
410
+ // Nullary tag constructors get turned into constants; n-ary tag
411
+ // constructors get turned into functions.
412
+ auto result_ty;
413
+ if ( _vec. len [ @ast. ty ] ( variant. args ) == 0 u) {
414
+ result_ty = plain_ty ( ty_tag ( tag_id) ) ;
415
+ } else {
416
+ // As above, tell ast_ty_to_ty() that trans_ty_item_to_ty()
417
+ // should be called to resolve named types.
418
+ auto f = bind trans_ty_item_id_to_ty ( id_to_ty_item,
419
+ item_to_ty, _) ;
420
+
421
+ let vec[ arg] args = vec ( ) ;
422
+ for ( @ast. ty arg_ast_ty in variant. args ) {
423
+ auto arg_ty = ast_ty_to_ty ( f, arg_ast_ty) ;
424
+ args += vec ( rec ( mode=ast. alias , ty=arg_ty) ) ;
425
+ }
426
+ result_ty = plain_ty ( ty_fn ( args, plain_ty ( ty_tag ( tag_id) ) ) ) ;
427
+ }
428
+
429
+ item_to_ty. insert ( variant. id , result_ty) ;
430
+ }
431
+ }
432
+
404
433
// First pass: collect all type item IDs.
405
434
auto module = crate . node . module ;
406
435
auto id_to_ty_item = @common. new_def_hash [ @ast. item ] ( ) ;
@@ -434,7 +463,9 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) {
434
463
case ( ast. item_mod ( _, _, _) ) {
435
464
result = it. node ;
436
465
}
437
- case ( ast. item_tag ( _, _, _, _) ) {
466
+ case ( ast. item_tag ( _, ?variants, _, ?tag_id) ) {
467
+ add_tag_variant_types ( id_to_ty_item, item_to_ty, tag_id,
468
+ variants) ;
438
469
result = it. node ;
439
470
}
440
471
}
@@ -1195,6 +1226,10 @@ fn check_expr(&fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
1195
1226
check ( fcx. ccx . item_types . contains_key ( id) ) ;
1196
1227
t = fcx. ccx . item_types . get ( id) ;
1197
1228
}
1229
+ case ( ast. def_variant ( _, ?variant_id) ) {
1230
+ check ( fcx. ccx . item_types . contains_key ( variant_id) ) ;
1231
+ t = fcx. ccx . item_types . get ( variant_id) ;
1232
+ }
1198
1233
case ( _) {
1199
1234
// FIXME: handle other names.
1200
1235
fcx. ccx . sess . unimpl ( "definition variant for: "
0 commit comments