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

Unified Diff: compiler/javatests/com/google/dart/compiler/resolver/NegativeResolverTest.java

Issue 10544022: Issue 3180. Report shadowing top-level elements by local 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
« no previous file with comments | « compiler/java/com/google/dart/compiler/resolver/Elements.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 c706b151db9fb82595e84cf2ae1a6e4d05b053c1..da4e27e491273ac5925bf9d330092090868500dd 100644
--- a/compiler/javatests/com/google/dart/compiler/resolver/NegativeResolverTest.java
+++ b/compiler/javatests/com/google/dart/compiler/resolver/NegativeResolverTest.java
@@ -443,6 +443,72 @@ public class NegativeResolverTest extends CompilerTestCase {
"duplicate top-level declaration 'FIELD foo' at Test.dart::2:5",
errors.get(1).getMessage());
}
+
+ /**
+ * Shadowing top-level element with local variable.
+ * <p>
+ * http://code.google.com/p/dart/issues/detail?id=3180
+ */
+ public void test_nameShadow_topLevel_localVariable_inFunction() {
+ checkSourceErrors(
+ makeCode(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {}",
+ "interface B {}",
+ "var foo;",
+ "main() {",
+ " var A;",
+ " var B;",
+ " var foo;",
+ "}",
+ ""),
+ errEx(ResolverErrorCode.DUPLICATE_LOCAL_VARIABLE_WARNING, 6, 7, 1),
+ errEx(ResolverErrorCode.DUPLICATE_LOCAL_VARIABLE_WARNING, 7, 7, 1),
+ errEx(ResolverErrorCode.DUPLICATE_LOCAL_VARIABLE_WARNING, 8, 7, 3));
+ assertEquals(
+ "Local variable 'A' is hiding 'CLASS A' at Test.dart:A:2:7",
+ errors.get(0).getMessage());
+ assertEquals(
+ "Local variable 'B' is hiding 'CLASS B' at Test.dart:B:3:11",
+ errors.get(1).getMessage());
+ assertEquals(
+ "Local variable 'foo' is hiding 'FIELD foo' at Test.dart::4:5",
+ errors.get(2).getMessage());
+ }
+
+ /**
+ * Shadowing top-level element with local variable.
+ * <p>
+ * http://code.google.com/p/dart/issues/detail?id=3180
+ */
+ public void test_nameShadow_topLevel_localVariable_inInstanceMethod() {
+ checkSourceErrors(
+ makeCode(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {}",
+ "interface B {}",
+ "var foo;",
+ "class Z {",
+ " m() {",
+ " var A;",
+ " var B;",
+ " var foo;",
+ " }",
+ "}",
+ ""),
+ errEx(ResolverErrorCode.DUPLICATE_LOCAL_VARIABLE_WARNING, 7, 9, 1),
+ errEx(ResolverErrorCode.DUPLICATE_LOCAL_VARIABLE_WARNING, 8, 9, 1),
+ errEx(ResolverErrorCode.DUPLICATE_LOCAL_VARIABLE_WARNING, 9, 9, 3));
+ assertEquals(
+ "Local variable 'A' is hiding 'CLASS A' at Test.dart:A:2:7",
+ errors.get(0).getMessage());
+ assertEquals(
+ "Local variable 'B' is hiding 'CLASS B' at Test.dart:B:3:11",
+ errors.get(1).getMessage());
+ assertEquals(
+ "Local variable 'foo' is hiding 'FIELD foo' at Test.dart::4:5",
+ errors.get(2).getMessage());
+ }
/**
* Multiple unnamed constructor definitions.
« no previous file with comments | « compiler/java/com/google/dart/compiler/resolver/Elements.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698