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

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

Issue 10581024: Issue 2382. Using a variable in a scope before its declared that shadows another variable (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 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/Resolver.java
diff --git a/compiler/java/com/google/dart/compiler/resolver/Resolver.java b/compiler/java/com/google/dart/compiler/resolver/Resolver.java
index 34dc319f31b878f4b088404db256c5ee4ae657c1..09fecaee5f63ff456aa176f821c52582a365794f 100644
--- a/compiler/java/com/google/dart/compiler/resolver/Resolver.java
+++ b/compiler/java/com/google/dart/compiler/resolver/Resolver.java
@@ -744,6 +744,8 @@ public class Resolver {
inFactoryContext(currentMethod),
TypeErrorCode.NO_SUCH_TYPE);
for (DartVariable variable : node.getVariables()) {
+ String name = variable.getVariableName();
+ getContext().getScope().removeDeclaredButNotReachedVariable(name);
Elements.setType(resolveVariable(variable, node.getModifiers()), type);
checkVariableStatement(node, variable, isImplicitlyInitialized);
}
@@ -794,6 +796,18 @@ public class Resolver {
public Element visitBlock(DartBlock x) {
getContext().pushScope("<block>");
addLabelToStatement(x);
+ // Remember names of Block variables.
+ for (DartStatement statement : x.getStatements()) {
+ if (statement instanceof DartVariableStatement) {
+ DartVariableStatement node = (DartVariableStatement) statement;
+ List<DartVariable> variables = node.getVariables();
+ for (DartVariable variable : variables) {
+ String name = variable.getVariableName();
+ getContext().getScope().addDeclaredButNotReachedVariable(name);
+ }
+ }
+ }
+ // Visit statements.
x.visitChildren(this);
getContext().popScope();
return null;
@@ -1013,6 +1027,11 @@ public class Resolver {
}
}
+ // May be local variable declared in lexical scope, but its declaration is not visited yet.
+ if (getContext().getScope().isDeclaredButNotReachedVariable(name)) {
+ onError(x, ResolverErrorCode.USING_LOCAL_VARIABLE_BEFORE_DECLARATION, x);
+ }
+
// If we we haven't resolved the identifier, it will be normalized to
// this.<identifier>.

Powered by Google App Engine
This is Rietveld 408576698