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

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

Issue 8846002: Tweaks for reporting duplicates, issue 519. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix for issue 647. Remove FIELD. Created 9 years 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/TopLevelElementBuilder.java
diff --git a/compiler/java/com/google/dart/compiler/resolver/TopLevelElementBuilder.java b/compiler/java/com/google/dart/compiler/resolver/TopLevelElementBuilder.java
index 526131c0b657aa6ee21a7440223beac3cc3f8803..122c74dea7ba53e6aea45edf743fbad9dbdf3e3b 100644
--- a/compiler/java/com/google/dart/compiler/resolver/TopLevelElementBuilder.java
+++ b/compiler/java/com/google/dart/compiler/resolver/TopLevelElementBuilder.java
@@ -10,6 +10,8 @@ import com.google.dart.compiler.DartCompilerContext;
import com.google.dart.compiler.DartCompilerListener;
import com.google.dart.compiler.ErrorCode;
import com.google.dart.compiler.ast.DartClass;
+import com.google.dart.compiler.ast.DartDeclaration;
+import com.google.dart.compiler.ast.DartExpression;
import com.google.dart.compiler.ast.DartField;
import com.google.dart.compiler.ast.DartFieldDefinition;
import com.google.dart.compiler.ast.DartFunctionTypeAlias;
@@ -94,16 +96,39 @@ public class TopLevelElementBuilder {
listener.onError(error);
}
- private void declare(Element element, DartCompilerListener listener, Scope scope) {
- Element originalElement = scope.declareElement(element.getName(), element);
- if (originalElement != null) {
- DartNode originalNode = originalElement.getNode();
- if (originalNode != null) {
- compilationError(listener, originalNode, ResolverErrorCode.DUPLICATE_DEFINITION,
- originalElement.getName());
+ private void declare(Element newElement, DartCompilerListener listener, Scope scope) {
+ Element oldElement = scope.declareElement(newElement.getName(), newElement);
+ // We had already node with such name, report duplicate.
+ if (oldElement != null) {
+ // Getter/setter can shared same name, but not setter/setter and getter/getter.
+ if (newElement.getModifiers().isAbstractField()
+ && oldElement.getModifiers().isAbstractField()) {
+ if (newElement.getModifiers().isGetter() && !oldElement.getModifiers().isGetter()) {
+ return;
+ }
+ if (newElement.getModifiers().isSetter() && !oldElement.getModifiers().isSetter()) {
+ return;
+ }
}
- compilationError(listener, element.getNode(), ResolverErrorCode.DUPLICATE_DEFINITION,
- originalElement.getName());
+ // Report two duplicate for both old/new nodes.
+ reportDuplicateDeclaration(listener, oldElement);
+ reportDuplicateDeclaration(listener, newElement);
+ }
+ }
+
+ /**
+ * Reports {@link ResolverErrorCode#DUPLICATE_TOP_LEVEL_DEFINITION} for given named element.
+ */
+ @SuppressWarnings("unchecked")
+ private void reportDuplicateDeclaration(DartCompilerListener listener, Element element) {
+ DartNode node = element.getNode();
+ if (node instanceof DartDeclaration) {
+ DartNode nameNode = ((DartDeclaration<DartExpression>) node).getName();
+ compilationError(
+ listener,
+ nameNode,
+ ResolverErrorCode.DUPLICATE_TOP_LEVEL_DEFINITION,
+ nameNode);
}
}

Powered by Google App Engine
This is Rietveld 408576698