diff --git a/src/rustc/metadata/decoder.rs b/src/rustc/metadata/decoder.rs index 7209d4e67311768c58b3c24d9827789d30b44e2f..8f25281f4a8cfcc25be683f76d01db09e8a588d1 100644 --- a/src/rustc/metadata/decoder.rs +++ b/src/rustc/metadata/decoder.rs @@ -546,7 +546,11 @@ fn read_path(d: ebml::doc) -> {path: str, pos: uint} { fn describe_def(items: ebml::doc, id: ast::def_id) -> str { if id.crate != ast::local_crate { ret "external"; } - ret item_family_to_str(item_family(find_item(id.node, items))); + let it = alt maybe_find_item(id.node, items) { + some(it) { it } + none { fail (#fmt("describe_def: item not found %?", id)); } + }; + ret item_family_to_str(item_family(it)); } fn item_family_to_str(fam: char) -> str { @@ -567,6 +571,8 @@ fn item_family_to_str(fam: char) -> str { 'i' { ret "impl"; } 'I' { ret "iface"; } 'C' { ret "class"; } + 'g' { ret "public field"; } + 'j' { ret "private field"; } } } diff --git a/src/rustc/metadata/encoder.rs b/src/rustc/metadata/encoder.rs index 7f2474e57ca97cc329bf294d5704ca065e5bc629..8390989e7dddc3e1d9193c535a997399be87d916 100644 --- a/src/rustc/metadata/encoder.rs +++ b/src/rustc/metadata/encoder.rs @@ -191,7 +191,7 @@ fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt, encode_name_and_def_id(ebml_w, it.ident, it.id); } ebml_w.wr_tag(tag_paths) {|| - // As in the res case, we add the same ident twice: for the + // We add the same ident twice: for the // class and for its ctor add_to_index(ebml_w, path, index, it.ident); encode_named_def_id(ebml_w, it.ident, @@ -422,8 +422,9 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: ebml::writer, id: node_id, path: ast_map::path, class_tps: [ty_param], items: [@class_member], - global_index: @mut[entry]) - -> [entry] { + global_index: @mut[entry]) -> [entry] { + /* Each class has its own index, since different classes + may have fields with the same name */ let index = @mut []; let tcx = ecx.tcx; for items.each {|ci| @@ -432,6 +433,7 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: ebml::writer, alt ci.node { instance_var(nm, _, mt, id, vis) { *index += [{val: id, pos: ebml_w.writer.tell()}]; + *global_index += [{val: id, pos: ebml_w.writer.tell()}]; ebml_w.start_tag(tag_items_data_item); #debug("encode_info_for_class: doing %s %d", *nm, id); encode_visibility(ebml_w, vis); @@ -446,8 +448,6 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: ebml::writer, alt m.vis { public { *index += [{val: m.id, pos: ebml_w.writer.tell()}]; - /* Not sure whether we really need to have two indices, - but it works for now -- tjc */ *global_index += [{val: m.id, pos: ebml_w.writer.tell()}]; let impl_path = path + [ast_map::path_name(m.ident)]; #debug("encode_info_for_class: doing %s %d", *m.ident, m.id); diff --git a/src/test/run-pass/issue-2192.rs b/src/test/run-pass/issue-2192.rs new file mode 100644 index 0000000000000000000000000000000000000000..2696327e77e5b330a5f587902acd0ec4f712f9b4 --- /dev/null +++ b/src/test/run-pass/issue-2192.rs @@ -0,0 +1,6 @@ +#[crate_type = "lib"]; + +class foo { + let mut x: int; + new(xx: int) { self.x = xx; } +}