@@ -151,7 +151,7 @@ enum dir { inside, outside, }
151
151
// when looking up a variable name that's not yet in scope to check
152
152
// if it's already bound to a enum.
153
153
enum namespace { ns_val( ns_value_type ) , ns_type, ns_module, }
154
- enum ns_value_type { ns_a_enum , ns_any_value, }
154
+ enum ns_value_type { ns_an_enum , ns_any_value, }
155
155
156
156
fn resolve_crate ( sess : session , amap : ast_map:: map , crate : @ast:: crate ) ->
157
157
{ def_map : def_map , exp_map : exp_map , impl_map : impl_map } {
@@ -469,7 +469,7 @@ fn resolve_names(e: @env, c: @ast::crate) {
469
469
variable a refers to a nullary enum. */
470
470
ast:: pat_ident ( p, none) {
471
471
alt lookup_in_scope ( * e, sc, p. span , path_to_ident ( p) ,
472
- ns_val ( ns_a_enum ) ) {
472
+ ns_val ( ns_an_enum ) ) {
473
473
some ( fnd@ast:: def_variant ( _, _) ) {
474
474
e. def_map . insert ( pat. id , fnd) ;
475
475
}
@@ -519,11 +519,16 @@ fn visit_item_with_scope(e: @env, i: @ast::item, sc: scopes, v: vt<scopes>) {
519
519
}
520
520
ast:: item_class ( tps, members, ctor_id, ctor_decl, ctor_block) {
521
521
visit:: visit_ty_params ( tps, sc, v) ;
522
- let ctor_scope = cons ( scope_fn_expr ( ctor_decl, ctor_id, tps) , @sc) ;
522
+ let class_scope = cons ( scope_item ( i) , @sc) ;
523
+ /* visit the constructor... */
524
+ visit_fn_with_scope ( e, visit:: fk_item_fn ( i. ident , tps) , ctor_decl,
525
+ ctor_block, ctor_block. span , ctor_id,
526
+ class_scope, v) ;
527
+ /* visit the items */
523
528
for cm in members {
524
529
alt cm. node . decl {
525
- class_method ( i) { visit_item_with_scope ( e, i, ctor_scope , v) ; }
526
- _ { } // instance var -- nothing to do
530
+ class_method ( i) { visit_item_with_scope ( e, i, class_scope , v) ; }
531
+ instance_var ( _ , t , _ , _ ) { v . visit_ty ( t , class_scope , v ) ; }
527
532
}
528
533
}
529
534
}
@@ -622,10 +627,10 @@ fn visit_local_with_scope(e: @env, loc: @local, sc:scopes, v:vt<scopes>) {
622
627
// to enum foo, or is it binding a new name foo?)
623
628
alt loc. node . pat . node {
624
629
pat_ident ( an_ident, _) {
625
- // Be sure to pass ns_a_enum to lookup_in_scope so that
630
+ // Be sure to pass ns_an_enum to lookup_in_scope so that
626
631
// if this is a name that's being shadowed, we don't die
627
632
alt lookup_in_scope ( * e, sc, loc. span ,
628
- path_to_ident ( an_ident) , ns_val ( ns_a_enum ) ) {
633
+ path_to_ident ( an_ident) , ns_val ( ns_an_enum ) ) {
629
634
some ( ast:: def_variant ( enum_id, variant_id) ) {
630
635
// Declaration shadows a enum that's in scope.
631
636
// That's an error.
@@ -804,7 +809,7 @@ fn ns_name(ns: namespace) -> str {
804
809
ns_val ( v) {
805
810
alt ( v) {
806
811
ns_any_value { "name" }
807
- ns_a_enum { "enum" }
812
+ ns_an_enum { "enum" }
808
813
}
809
814
}
810
815
ns_module { "modulename" }
@@ -1000,6 +1005,21 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
1000
1005
ast:: item_native_mod ( m) {
1001
1006
ret lookup_in_local_native_mod ( e, it. id , sp, name, ns) ;
1002
1007
}
1008
+ ast:: item_class ( tps, members, ctor_id, _, _) {
1009
+ if ns == ns_type {
1010
+ ret lookup_in_ty_params ( e, name, tps) ;
1011
+ }
1012
+ if ns == ns_val ( ns_any_value) && name == it. ident {
1013
+ ret some ( ast:: def_fn ( local_def ( ctor_id) ,
1014
+ ast:: impure_fn) ) ;
1015
+ }
1016
+ if ns == ns_val ( ns_any_value) {
1017
+ ret lookup_in_class ( local_def ( it. id ) ,
1018
+ members, name) ;
1019
+ }
1020
+ // FIXME: AST allows other items to appear in a class,
1021
+ // but that might not be wise
1022
+ }
1003
1023
_ { }
1004
1024
}
1005
1025
}
@@ -1071,7 +1091,7 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
1071
1091
/* If we were looking for a enum, at this point
1072
1092
we know it's bound to a non-enum value, and
1073
1093
we can return none instead of failing */
1074
- ns_a_enum { ret none; }
1094
+ ns_an_enum { ret none; }
1075
1095
_ { "attempted dynamic environment-capture" }
1076
1096
}
1077
1097
}
@@ -1146,6 +1166,29 @@ fn lookup_in_fn(e: env, name: ident, decl: ast::fn_decl,
1146
1166
}
1147
1167
}
1148
1168
1169
+ /*
1170
+ FIXME: not sure about this code. maybe this should be handled
1171
+ using the mod_index stuff
1172
+ */
1173
+ fn lookup_in_class ( parent_id : def_id ,
1174
+ members : [ @class_item ] , name : ident )
1175
+ -> option < def > {
1176
+ for m in members {
1177
+ alt m. node . decl {
1178
+ instance_var ( v_name, _, _, id) {
1179
+ if v_name == name {
1180
+ ret some ( def_class_field ( parent_id, local_def ( id) ) ) ;
1181
+ }
1182
+ }
1183
+ class_method ( i) {
1184
+ if i. ident == name {
1185
+ ret some ( def_class_method ( parent_id, local_def ( i. id ) ) ) ;
1186
+ }
1187
+ }
1188
+ }
1189
+ }
1190
+ ret none;
1191
+ }
1149
1192
1150
1193
fn lookup_in_block ( e : env , name : ident , sp : span , b : ast:: blk_ , pos : uint ,
1151
1194
loc_pos : uint , ns : namespace ) -> option < def > {
@@ -1430,7 +1473,7 @@ fn lookup_in_globs(e: env, globs: [glob_imp_def], sp: span, id: ident,
1430
1473
if vec:: len ( matches) == 0 u {
1431
1474
ret none;
1432
1475
}
1433
- else if vec:: len ( matches) == 1 u || ns == ns_val ( ns_a_enum ) {
1476
+ else if vec:: len ( matches) == 1 u || ns == ns_val ( ns_an_enum ) {
1434
1477
ret some ( matches[ 0 ] . def ) ;
1435
1478
} else {
1436
1479
for match: glob_imp_def in matches {
@@ -1449,7 +1492,7 @@ fn lookup_glob_in_mod(e: env, info: @indexed_mod, sp: span, id: ident,
1449
1492
if !info. glob_imported_names . contains_key ( id) {
1450
1493
info. glob_imported_names . insert ( id, glob_resolving ( sp) ) ;
1451
1494
// kludge
1452
- let val_ns = if wanted_ns == ns_val ( ns_a_enum ) { ns_val ( ns_a_enum ) }
1495
+ let val_ns = if wanted_ns == ns_val ( ns_an_enum ) { ns_val ( ns_an_enum ) }
1453
1496
else { ns_val ( ns_any_value) } ;
1454
1497
let globs = info. glob_imports ;
1455
1498
let val = lookup_in_globs ( e, globs, sp, id, val_ns, dr) ;
@@ -1615,7 +1658,7 @@ fn index_nmod(md: ast::native_mod) -> mod_index {
1615
1658
// External lookups
1616
1659
fn ns_for_def ( d : def ) -> namespace {
1617
1660
alt d {
1618
- ast : : def_variant ( _, _) { ns_val ( ns_a_enum ) }
1661
+ ast : : def_variant ( _, _) { ns_val ( ns_an_enum ) }
1619
1662
ast:: def_fn ( _, _) | ast:: def_self ( _) |
1620
1663
ast:: def_const ( _) | ast:: def_arg ( _, _) | ast:: def_local ( _) |
1621
1664
ast:: def_upvar ( _, _, _) | ast:: def_self ( _) |
@@ -1632,7 +1675,7 @@ fn ns_for_def(d: def) -> namespace {
1632
1675
// a enum
1633
1676
fn ns_ok ( wanted : namespace , actual : namespace ) -> bool {
1634
1677
alt actual {
1635
- ns_val( ns_a_enum ) {
1678
+ ns_val( ns_an_enum ) {
1636
1679
alt wanted {
1637
1680
ns_val( _) { true }
1638
1681
_ { false }
0 commit comments