@@ -919,9 +919,42 @@ fn demand_pat(&@fn_ctxt fcx, @ty.t expected, @ast.pat pat) -> @ast.pat {
919
919
// acquire here with the type parameters provided to us by
920
920
// "expected".
921
921
922
+ // Grab the values for the type parameters of the tag from the
923
+ // expected type.
924
+ let vec[ @ty. t] typaram_bindings = vec ( ) ; // FIXME: typestate botch
925
+ alt ( expected. struct ) {
926
+ case ( ty. ty_tag ( _, ?tps) ) { typaram_bindings = tps; }
927
+ case ( _) {
928
+ log "tag pattern didn't have tag type?!" ;
929
+ fail;
930
+ }
931
+ }
932
+
933
+ // Get the item corresponding to the tag and its type.
922
934
auto vdef = option. get [ ast. variant_def ] ( vdef_opt) ;
923
935
auto variant_ty = fcx. ccx . item_types . get ( vdef. _1 ) ;
924
936
937
+ // FIXME: typestate botch
938
+ let option. t[ @ast. item] item_opt = none[ @ast. item ] ;
939
+ alt ( fcx. ccx . item_items . get ( vdef. _0 ) ) {
940
+ case ( any_item_rust ( ?it) ) { item_opt = some[ @ast. item ] ( it) ; }
941
+ case ( _) {
942
+ log "tag item isn't a Rust item?!" ;
943
+ fail;
944
+ }
945
+ }
946
+ let @ast. item item = option. get [ @ast. item ] ( item_opt) ;
947
+
948
+ // Get the IDs of the type parameters from that item.
949
+ let vec[ ast. ty_param ] ty_params = vec ( ) ; // FIXME: typestate botch
950
+ alt ( item. node ) {
951
+ case ( ast. item_tag ( _, _, ?tps, _) ) { ty_params = tps; }
952
+ case ( _) {
953
+ log "tag's corresponding item isn't a tag?!" ;
954
+ fail;
955
+ }
956
+ }
957
+
925
958
auto subpats_len = _vec. len [ @ast. pat ] ( subpats) ;
926
959
alt ( variant_ty. struct ) {
927
960
case ( ty. ty_tag ( _, _) ) {
@@ -930,10 +963,14 @@ fn demand_pat(&@fn_ctxt fcx, @ty.t expected, @ast.pat pat) -> @ast.pat {
930
963
p_1 = ast. pat_tag ( id, subpats, vdef_opt, ast. ann_type ( t) ) ;
931
964
}
932
965
case ( ty. ty_fn ( _, ?args, ?tag_ty) ) {
966
+ // N-ary tag variant.
933
967
let vec[ @ast. pat] new_subpats = vec ( ) ;
934
968
auto i = 0 u;
935
969
for ( arg a in args) {
936
- auto new_subpat = demand_pat( fcx, a. ty, subpats. ( i) ) ;
970
+ auto arg_ty = ty. substitute_ty_params( ty_params,
971
+ typaram_bindings, a. ty) ;
972
+ auto new_subpat = demand_pat( fcx, arg_ty,
973
+ subpats. ( i) ) ;
937
974
new_subpats += vec( new_subpat) ;
938
975
i += 1 u;
939
976
}
@@ -1260,14 +1297,13 @@ fn check_pat(&@fn_ctxt fcx, @ast.pat pat) -> @ast.pat {
1260
1297
new_subpats += vec ( check_pat ( fcx, subpat) ) ;
1261
1298
}
1262
1299
1263
- auto ann = ast. ann_type ( tag_ty) ;
1300
+ auto tag_ty_g = generalize_ty ( fcx. ccx , tag_ty) ;
1301
+ auto ann = ast. ann_type ( tag_ty_g) ;
1264
1302
new_pat = ast. pat_tag ( p, new_subpats, vdef_opt, ann) ;
1265
1303
}
1266
1304
1267
1305
// Nullary variants have tag types.
1268
- case ( ty. ty_tag ( ?tid, _) ) {
1269
- // TODO: ty params
1270
-
1306
+ case ( ty. ty_tag ( ?tid, ?tps) ) {
1271
1307
auto subpats_len = _vec. len [ @ast. pat ] ( subpats) ;
1272
1308
if ( subpats_len > 0 u) {
1273
1309
// TODO: pluralize properly
@@ -1281,7 +1317,14 @@ fn check_pat(&@fn_ctxt fcx, @ast.pat pat) -> @ast.pat {
1281
1317
fail; // TODO: recover
1282
1318
}
1283
1319
1284
- let vec[ @ty. t] tys = vec ( ) ; // FIXME
1320
+ // Add the appropriate number of type variables.
1321
+ let vec[ @ty. t] tys = vec ( ) ;
1322
+ auto i = 0 u;
1323
+ while ( i < _vec. len [ @ty. t] ( tps) ) {
1324
+ tys += vec ( next_ty_var ( fcx. ccx ) ) ;
1325
+ i += 1 u;
1326
+ }
1327
+
1285
1328
auto ann = ast. ann_type ( plain_ty ( ty. ty_tag ( tid, tys) ) ) ;
1286
1329
new_pat = ast. pat_tag ( p, subpats, vdef_opt, ann) ;
1287
1330
}
0 commit comments