Merge pull request #3252 from Vincent-Belliard/issue_2356

implements issue #2356
This commit is contained in:
Tim Chevalier 2012-08-25 08:10:16 -07:00
commit 390a31a57d

View File

@ -4069,6 +4069,47 @@ fn resolve_item_by_identifier_in_lexical_scope(ident: ident,
}
}
fn name_exists_in_scope_class(name: &str) -> bool {
let mut i = self.type_ribs.len();
while i != 0 {
i -= 1;
let rib = self.type_ribs.get_elt(i);
match rib.kind {
MethodRibKind(node_id, _) =>
for vec::each(self.crate.node.module.items) |item| {
if item.id == node_id {
match item.node {
item_class(class_def, _) => {
for vec::each(class_def.fields) |field| {
match field.node.kind {
syntax::ast::unnamed_field
=> {},
syntax::ast::named_field(ident, _, _)
=> {
if str::eq_slice(self.session.str_of(ident),
name) {
return true
}
}
}
}
for vec::each(class_def.methods) |method| {
if str::eq_slice(self.session.str_of(method.ident),
name) {
return true
}
}
}
_ => {}
}
}
},
_ => {}
}
}
return false;
}
fn resolve_expr(expr: @expr, visitor: ResolveVisitor) {
// First, record candidate traits for this expression if it could
// result in the invocation of a method call.
@ -4093,12 +4134,21 @@ fn resolve_expr(expr: @expr, visitor: ResolveVisitor) {
self.record_def(expr.id, def);
}
none => {
self.session.span_err(
expr.span,
fmt!("unresolved name: %s",
connect(path.idents.map(
|x| self.session.str_of(x)),
~"::")));
let wrong_name =
connect(path.idents.map(
|x| self.session.str_of(x)), ~"::") ;
if self.name_exists_in_scope_class(wrong_name) {
self.session.span_err(expr.span,
fmt!("unresolved name: %s. \
Did you mean: self.%s",
wrong_name,
wrong_name));
}
else {
self.session.span_err(expr.span,
fmt!("unresolved name: %s",
wrong_name));
}
}
}