@@ -142,6 +142,7 @@ type env =
142
142
mutable data: [ ast:: node_id ] } ,
143
143
mutable reported: [ { ident: str , sc : scope } ] ,
144
144
mutable ignored_imports: [ node_id ] ,
145
+ mutable current_tp: option:: t < uint > ,
145
146
sess : session } ;
146
147
147
148
@@ -168,6 +169,7 @@ fn resolve_crate(sess: session, amap: ast_map::map, crate: @ast::crate) ->
168
169
used_imports : { mutable track: false , mutable data: [ ] } ,
169
170
mutable reported: [ ] ,
170
171
mutable ignored_imports: [ ] ,
172
+ mutable current_tp: none,
171
173
sess: sess} ;
172
174
map_crate ( e, crate ) ;
173
175
resolve_imports ( * e) ;
@@ -336,6 +338,7 @@ fn resolve_names(e: @env, c: @ast::crate) {
336
338
visit_pat: bind walk_pat ( e, _, _, _) ,
337
339
visit_expr: bind walk_expr ( e, _, _, _) ,
338
340
visit_ty: bind walk_ty ( e, _, _, _) ,
341
+ visit_ty_params: bind walk_tps ( e, _, _, _) ,
339
342
visit_constr: bind walk_constr ( e, _, _, _, _, _) ,
340
343
visit_fn: bind visit_fn_with_scope ( e, _, _, _, _, _, _, _)
341
344
with * visit:: default_visitor ( ) } ;
@@ -369,6 +372,20 @@ fn resolve_names(e: @env, c: @ast::crate) {
369
372
_ { }
370
373
}
371
374
}
375
+ fn walk_tps ( e : @env , tps : [ ast:: ty_param ] , sc : scopes , v : vt < scopes > ) {
376
+ let outer_current_tp = e. current_tp , current = 0 u;
377
+ for tp in tps {
378
+ e. current_tp = some ( current) ;
379
+ for bound in * tp. bounds {
380
+ alt bound {
381
+ bound_iface( t) { v. visit_ty ( t, sc, v) ; }
382
+ _ { }
383
+ }
384
+ }
385
+ current += 1 u;
386
+ }
387
+ e. current_tp = outer_current_tp;
388
+ }
372
389
fn walk_constr ( e : @env , p : @ast:: path , sp : span , id : node_id , sc : scopes ,
373
390
_v : vt < scopes > ) {
374
391
maybe_insert ( e, id, lookup_path_strict ( * e, sc, sp, p. node , ns_value) ) ;
@@ -806,14 +823,14 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
806
823
scope_item ( it) {
807
824
alt it. node {
808
825
ast:: item_obj ( ob, ty_params, _) {
809
- ret lookup_in_obj ( name, ob, ty_params, ns, it. id ) ;
826
+ ret lookup_in_obj ( e , name, ob, ty_params, ns, it. id ) ;
810
827
}
811
- ast:: item_impl ( ty_params , _, _, _) {
812
- if ns == ns_type { ret lookup_in_ty_params ( name, ty_params ) ; }
828
+ ast:: item_impl ( tps , _, _, _) {
829
+ if ns == ns_type { ret lookup_in_ty_params ( e , name, tps ) ; }
813
830
}
814
831
ast:: item_iface ( tps, _) | ast:: item_tag ( _, tps) |
815
832
ast:: item_ty ( _, tps) {
816
- if ns == ns_type { ret lookup_in_ty_params ( name, tps) ; }
833
+ if ns == ns_type { ret lookup_in_ty_params ( e , name, tps) ; }
817
834
}
818
835
ast:: item_mod ( _) {
819
836
ret lookup_in_local_mod ( e, it. id , sp, name, ns, inside) ;
@@ -828,19 +845,19 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
828
845
if ( name == "self" && ns == ns_value) {
829
846
ret some ( ast:: def_self ( local_def ( id) ) ) ;
830
847
} else if ns == ns_type {
831
- ret lookup_in_ty_params ( name, tps) ;
848
+ ret lookup_in_ty_params ( e , name, tps) ;
832
849
}
833
850
}
834
851
scope_native_item ( it) {
835
852
alt it. node {
836
853
ast:: native_item_fn ( decl, ty_params) {
837
- ret lookup_in_fn ( name, decl, ty_params, ns) ;
854
+ ret lookup_in_fn ( e , name, decl, ty_params, ns) ;
838
855
}
839
856
}
840
857
}
841
858
scope_bare_fn ( decl, _, ty_params) |
842
859
scope_fn_expr ( decl, _, ty_params) {
843
- ret lookup_in_fn ( name, decl, ty_params, ns) ;
860
+ ret lookup_in_fn ( e , name, decl, ty_params, ns) ;
844
861
}
845
862
scope_loop ( local) {
846
863
if ns == ns_value {
@@ -915,13 +932,13 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
915
932
e. sess . bug ( "reached unreachable code in lookup_in_scope" ) ; // sigh
916
933
}
917
934
918
- fn lookup_in_ty_params ( name : ident , ty_params : [ ast:: ty_param ] ) ->
919
- option:: t < def > {
935
+ fn lookup_in_ty_params ( e : env , name : ident , ty_params : [ ast:: ty_param ] )
936
+ -> option:: t < def > {
920
937
let n = 0 u;
921
938
for tp: ast:: ty_param in ty_params {
922
- if str:: eq ( tp. ident , name) {
923
- ret some ( ast :: def_ty_param ( local_def ( tp . id ) , n ) ) ;
924
- }
939
+ if str:: eq ( tp. ident , name) && alt e . current_tp {
940
+ some ( cur ) { n < cur } none . { true }
941
+ } { ret some ( ast :: def_ty_param ( local_def ( tp . id ) , n ) ) ; }
925
942
n += 1 u;
926
943
}
927
944
ret none:: < def > ;
@@ -936,7 +953,8 @@ fn lookup_in_pat(name: ident, pat: @ast::pat) -> option::t<def_id> {
936
953
ret found;
937
954
}
938
955
939
- fn lookup_in_fn ( name : ident , decl : ast:: fn_decl , ty_params : [ ast:: ty_param ] ,
956
+ fn lookup_in_fn ( e : env , name : ident , decl : ast:: fn_decl ,
957
+ ty_params : [ ast:: ty_param ] ,
940
958
ns : namespace ) -> option:: t < def > {
941
959
alt ns {
942
960
ns_value. {
@@ -947,12 +965,13 @@ fn lookup_in_fn(name: ident, decl: ast::fn_decl, ty_params: [ast::ty_param],
947
965
}
948
966
ret none :: < def > ;
949
967
}
950
- ns_type. { ret lookup_in_ty_params ( name, ty_params) ; }
968
+ ns_type. { ret lookup_in_ty_params ( e , name, ty_params) ; }
951
969
_ { ret none:: < def > ; }
952
970
}
953
971
}
954
972
955
- fn lookup_in_obj ( name : ident , ob : ast:: _obj , ty_params : [ ast:: ty_param ] ,
973
+ fn lookup_in_obj ( e : env , name : ident , ob : ast:: _obj ,
974
+ ty_params : [ ast:: ty_param ] ,
956
975
ns : namespace , id : node_id ) -> option:: t < def > {
957
976
alt ns {
958
977
ns_value. {
@@ -964,7 +983,7 @@ fn lookup_in_obj(name: ident, ob: ast::_obj, ty_params: [ast::ty_param],
964
983
}
965
984
ret none:: < def > ;
966
985
}
967
- ns_type. { ret lookup_in_ty_params ( name, ty_params) ; }
986
+ ns_type. { ret lookup_in_ty_params ( e , name, ty_params) ; }
968
987
_ { ret none:: < def > ; }
969
988
}
970
989
}
0 commit comments