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

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

Issue 8966029: Report errors and warnings for hiding elements, issue 572. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes for comments 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/ResolutionContext.java
diff --git a/compiler/java/com/google/dart/compiler/resolver/ResolutionContext.java b/compiler/java/com/google/dart/compiler/resolver/ResolutionContext.java
index df9aa182272c2faccabf58ea8f33a8edae91a94c..c9a3d9e86e2cc0e710c27a53c436d1075fd04982 100644
--- a/compiler/java/com/google/dart/compiler/resolver/ResolutionContext.java
+++ b/compiler/java/com/google/dart/compiler/resolver/ResolutionContext.java
@@ -66,12 +66,31 @@ public class ResolutionContext implements ResolutionErrorListener {
return scope;
}
- void declare(Element element) {
- Element existingElement = scope.declareElement(element.getName(), element);
- if (existingElement != null) {
- onError(element.getNode(), ResolverErrorCode.DUPLICATE_TOP_LEVEL_DEFINITION,
- element.getName());
+ void declare(Element element, ErrorCode errorCode, ErrorCode warningCode) {
+ String name = element.getName();
+ Element existingLocalElement = scope.findLocalElement(name);
+ // Check for duplicate declaration in the enclosing scope.
+ if (existingLocalElement == null && warningCode != null) {
+ Element existingElement = scope.findElement(scope.getLibrary(), name);
+ if (existingElement != null) {
+ if (!Elements.isConstructorParameter(element)
+ && !Elements.isParameterOfMethodWithoutBody(element)
+ && !(Elements.isStaticContext(element) && !Elements.isStaticContext(existingElement))
+ && !existingElement.getModifiers().isAbstractField()) {
+ DartNode nameNode = Elements.getNameNode(element);
+ String existingLocation = Elements.getRelativeElementLocation(element, existingElement);
+ onError(nameNode, warningCode, name, existingElement, existingLocation);
+ }
+ }
+ }
+ // Check for duplicate declaration in the same scope.
+ if (existingLocalElement != null && errorCode != null) {
+ DartNode nameNode = Elements.getNameNode(element);
+ String existingLocation = Elements.getRelativeElementLocation(element, existingLocalElement);
+ onError(nameNode, errorCode, name, existingLocation);
}
+ // Declare, may be hide existing element.
+ scope.declareElement(name, element);
}
void pushScope(String name) {
@@ -245,7 +264,10 @@ public class ResolutionContext implements ResolutionErrorListener {
MethodElement declareFunction(DartFunctionExpression node) {
MethodElement element = Elements.methodFromFunctionExpression(node, Modifiers.NONE);
if (node.getFunctionName() != null) {
- declare(element);
+ declare(
+ element,
+ ResolverErrorCode.DUPLICATE_FUNCTION_EXPRESSION,
+ ResolverErrorCode.DUPLICATE_FUNCTION_EXPRESSION_WARNING);
}
return element;
}

Powered by Google App Engine
This is Rietveld 408576698