Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(570)

Unified Diff: compiler/java/com/google/dart/compiler/resolver/MemberBuilder.java

Issue 10735039: Issue 3986. Class member cannot have the same name as the class (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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?";

Powered by Google App Engine
This is Rietveld 408576698