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

Unified Diff: compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java

Issue 11419186: Allow not only 'Iterator iterator()' but also 'Iterator iterator' (field). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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/type/TypeAnalyzerCompilerTest.java
diff --git a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
index dd81e86740787feb28d3faf6b5496ad0148f76cb..fd5391c207c3dbce31a5b6058ff6558d98247791 100644
--- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
@@ -5695,4 +5695,74 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
assertErrors(result.getErrors(),
errEx(ResolverErrorCode.VARIABLE_REFERENCES_SAME_NAME_IN_INITIALIZER, 3, 11, 1));
}
+
+ public void test_ForEachStatement_method() throws Exception {
+ AnalyzeLibraryResult result = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {",
+ " Iterator<int> iterator() {}",
+ "}",
+ "main() {",
+ " A a = new A();",
+ " for (int v in a) {}",
+ "}",
+ "");
+ assertErrors(result.getErrors());
+ }
+
+ public void test_ForEachStatement_negative_method_invalidReturnType() throws Exception {
+ AnalyzeLibraryResult result = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {",
+ " int iterator() {}",
+ "}",
+ "main() {",
+ " A a = new A();",
+ " for (int v in a) {}",
+ "}",
+ "");
+ assertErrors(
+ result.getErrors(),
+ errEx(TypeErrorCode.FOR_IN_WITH_INVALID_ITERATOR_RETURN_TYPE, 7, 17, 1));
+ }
+
+ /**
+ * It was negative test, but in the new <code>Iterator</code> field should be also supported.
+ */
+ public void test_ForEachStatement_field() throws Exception {
+ AnalyzeLibraryResult result = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {",
+ " Iterator iterator;",
+ "}",
+ "main() {",
+ " A a = new A();",
+ " for (int v in a) {}",
+ "}",
+ "");
+ assertErrors(result.getErrors());
+// Map<String, ClassNodeElement> fieldNotMethod = loadSource(
+// "class A {",
+// " int iterator;",
+// "}",
+// "class B {",
+// " main() { for (int i in new A()) {}}",
+// "}");
+// analyzeClasses(fieldNotMethod, TypeErrorCode.FOR_IN_WITH_ITERATOR_FIELD);
+ }
+
+ public void test_ForEachStatement_negative_field_invalidReturnType() throws Exception {
+ AnalyzeLibraryResult result = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {",
+ " int iterator;",
+ "}",
+ "main() {",
+ " A a = new A();",
+ " for (int v in a) {}",
+ "}",
+ "");
+ assertErrors(result.getErrors(),
+ errEx(TypeErrorCode.FOR_IN_WITH_INVALID_ITERATOR_RETURN_TYPE, 7, 17, 1));
+ }
}

Powered by Google App Engine
This is Rietveld 408576698