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; |
} |