Index: compiler/java/com/google/dart/compiler/resolver/MemberBuilder.java |
diff --git a/compiler/java/com/google/dart/compiler/resolver/MemberBuilder.java b/compiler/java/com/google/dart/compiler/resolver/MemberBuilder.java |
index f636a9eb9ecdbd2a075fb07dd6a0f100088c2838..dbf471d9ecdd4427d582d1b7ae718066eccd68c4 100644 |
--- a/compiler/java/com/google/dart/compiler/resolver/MemberBuilder.java |
+++ b/compiler/java/com/google/dart/compiler/resolver/MemberBuilder.java |
@@ -480,12 +480,14 @@ public class MemberBuilder { |
private void addField(EnclosingElement holder, FieldNodeElement element) { |
if (holder != null) { |
checkUniqueName(holder, element); |
+ checkMemberNameNotSameAsEnclosingClassName(holder, element); |
Elements.addField(holder, element); |
} |
} |
private void addMethod(EnclosingElement holder, MethodNodeElement element) { |
checkUniqueName(holder, element); |
+ checkMemberNameNotSameAsEnclosingClassName(holder, element); |
Elements.addMethod(holder, element); |
} |
@@ -589,6 +591,14 @@ public class MemberBuilder { |
} |
} |
+ private void checkMemberNameNotSameAsEnclosingClassName(EnclosingElement holder, Element e) { |
+ if (ElementKind.of(holder) == ElementKind.CLASS) { |
+ if (Objects.equal(holder.getName(), e.getName())) { |
+ resolutionError(e.getNameLocation(), ResolverErrorCode.MEMBER_WITH_NAME_OF_CLASS); |
+ } |
+ } |
+ } |
+ |
private void checkUniqueName(EnclosingElement holder, Element e) { |
Element other = lookupElementByName(holder, e.getName(), e.getModifiers()); |
assert e != other : "forgot to call checkUniqueName() before adding to the class?"; |