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

Unified Diff: compiler/javatests/com/google/dart/compiler/resolver/NegativeResolverTest.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/javatests/com/google/dart/compiler/resolver/NegativeResolverTest.java
diff --git a/compiler/javatests/com/google/dart/compiler/resolver/NegativeResolverTest.java b/compiler/javatests/com/google/dart/compiler/resolver/NegativeResolverTest.java
index da4e27e491273ac5925bf9d330092090868500dd..589eb473666452ca6dc190cc3e0c09b4bbab3231 100644
--- a/compiler/javatests/com/google/dart/compiler/resolver/NegativeResolverTest.java
+++ b/compiler/javatests/com/google/dart/compiler/resolver/NegativeResolverTest.java
@@ -670,6 +670,29 @@ public class NegativeResolverTest extends CompilerTestCase {
errEx(ResolverErrorCode.DUPLICATE_LOCAL_VARIABLE_WARNING, 6, 11, 1));
}
+ /**
+ * Here we have two local variables: one in "main" and one in the scope on "block". However
+ * variables are declared in lexical scopes, i.e. in "block", so using it before declaration is
+ * error.
+ * <p>
+ * http://code.google.com/p/dart/issues/detail?id=2382
+ */
+ public void test_useVariable_beforeDeclaration_inLexicalScope() throws Exception {
+ checkSourceErrors(
+ makeCode(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "main() {",
+ " var x;",
+ " {",
+ " x = 1;",
+ " var x;",
+ " }",
+ "}",
+ ""),
+ errEx(ResolverErrorCode.USING_LOCAL_VARIABLE_BEFORE_DECLARATION, 5, 5, 1),
+ errEx(ResolverErrorCode.DUPLICATE_LOCAL_VARIABLE_WARNING, 6, 9, 1));
+ }
+
public void test_nameShadow_field_variable() {
checkSourceErrors(
makeCode(

Powered by Google App Engine
This is Rietveld 408576698