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>. |