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

Unified Diff: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ScopedVisitor.java

Issue 22846005: Report StaticWarningCode.UNDEFINED_IDENTIFIER when name is hidden, but not defined yet in block. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ScopedVisitor.java
diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ScopedVisitor.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ScopedVisitor.java
index c2145c2ff629575961c8735ac8909235968e6c1c..0d052c5d63140c528582ef2f6d6aaaf3eccac054 100644
--- a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ScopedVisitor.java
+++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/ScopedVisitor.java
@@ -25,6 +25,7 @@ import com.google.dart.engine.ast.FieldDeclaration;
import com.google.dart.engine.ast.ForEachStatement;
import com.google.dart.engine.ast.ForStatement;
import com.google.dart.engine.ast.FunctionDeclaration;
+import com.google.dart.engine.ast.FunctionDeclarationStatement;
import com.google.dart.engine.ast.FunctionExpression;
import com.google.dart.engine.ast.FunctionTypeAlias;
import com.google.dart.engine.ast.IfStatement;
@@ -40,9 +41,11 @@ import com.google.dart.engine.ast.SwitchMember;
import com.google.dart.engine.ast.SwitchStatement;
import com.google.dart.engine.ast.TopLevelVariableDeclaration;
import com.google.dart.engine.ast.VariableDeclaration;
+import com.google.dart.engine.ast.VariableDeclarationStatement;
import com.google.dart.engine.ast.WhileStatement;
import com.google.dart.engine.ast.visitor.GeneralizingASTVisitor;
import com.google.dart.engine.element.CompilationUnitElement;
+import com.google.dart.engine.element.Element;
import com.google.dart.engine.element.ExecutableElement;
import com.google.dart.engine.element.LabelElement;
import com.google.dart.engine.element.LibraryElement;
@@ -155,7 +158,9 @@ public abstract class ScopedVisitor extends GeneralizingASTVisitor<Void> {
public Void visitBlock(Block node) {
Scope outerScope = nameScope;
try {
- nameScope = new EnclosedScope(nameScope);
+ EnclosedScope enclosedScope = new EnclosedScope(nameScope);
+ hideNamesDefinedInBlock(enclosedScope, node);
+ nameScope = enclosedScope;
super.visitBlock(node);
} finally {
nameScope = outerScope;
@@ -565,4 +570,26 @@ public abstract class ScopedVisitor extends GeneralizingASTVisitor<Void> {
}
return outerScope;
}
+
+ /**
+ * Marks the local declarations of the given {@link Block} hidden in the enclosing scope.
+ * According to the scoping rules name is hidden if block defines it, but name is defined after
+ * its declaration statement.
+ */
+ private void hideNamesDefinedInBlock(EnclosedScope scope, Block block) {
+ for (Statement statement : block.getStatements()) {
+ if (statement instanceof VariableDeclarationStatement) {
+ VariableDeclarationStatement vds = (VariableDeclarationStatement) statement;
+ for (VariableDeclaration variableDeclaration : vds.getVariables().getVariables()) {
+ Element element = variableDeclaration.getElement();
+ scope.hide(element);
+ }
+ }
+ if (statement instanceof FunctionDeclarationStatement) {
+ FunctionDeclarationStatement fds = (FunctionDeclarationStatement) statement;
+ Element element = fds.getFunctionDeclaration().getElement();
+ scope.hide(element);
+ }
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698