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

Unified Diff: compiler/java/com/google/dart/compiler/resolver/Scope.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/Scope.java
diff --git a/compiler/java/com/google/dart/compiler/resolver/Scope.java b/compiler/java/com/google/dart/compiler/resolver/Scope.java
index ae4fd3c6193e527f666f6ca85e49d4d6fd5da523..fe8d9d6b4ba60141b81aac65e04099ba5fb8886c 100644
--- a/compiler/java/com/google/dart/compiler/resolver/Scope.java
+++ b/compiler/java/com/google/dart/compiler/resolver/Scope.java
@@ -5,12 +5,16 @@
package com.google.dart.compiler.resolver;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.Sets;
+import com.google.dart.compiler.ast.DartBlock;
import com.google.dart.compiler.ast.DartIdentifier;
+import com.google.dart.compiler.ast.DartVariableStatement;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* A scope used by {@link Resolver}.
@@ -18,6 +22,7 @@ import java.util.Map;
public class Scope {
private final Map<String, Element> elements = new LinkedHashMap<String, Element>();
+ private final Set<String> declaredButNotReachedVariables = Sets.newHashSet();
private final Scope parent;
private final String name;
private List<LabelElement> labels;
@@ -86,6 +91,29 @@ public class Scope {
public Map<String, Element> getElements() {
return elements;
}
+
+ /**
+ * @return <code>true</code> if local variable with given name is declared in the lexical context
+ * of {@link DartBlock}, but corresponding {@link DartVariableStatement} is not visited
+ * yet. So, using this variable is error.
+ */
+ public boolean isDeclaredButNotReachedVariable(String name) {
+ return declaredButNotReachedVariables.contains(name);
+ }
+
+ /**
+ * @see #isDeclaredButNotReachedVariable(String)
+ */
+ public void addDeclaredButNotReachedVariable(String name) {
+ declaredButNotReachedVariables.add(name);
+ }
+
+ /**
+ * @see #isDeclaredButNotReachedVariable(String)
+ */
+ public void removeDeclaredButNotReachedVariable(String name) {
+ declaredButNotReachedVariables.remove(name);
+ }
public String getName() {
return name;

Powered by Google App Engine
This is Rietveld 408576698