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

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

Issue 8322014: Adds static type checking to the foreach loop. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased past r505 (Array -> List in TATs) Created 9 years, 2 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/javatests/com/google/dart/compiler/type/TypeAnalyzerTest.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/type/TypeTestCase.java
diff --git a/compiler/javatests/com/google/dart/compiler/type/TypeTestCase.java b/compiler/javatests/com/google/dart/compiler/type/TypeTestCase.java
index e9342deb1b4670d992d5d957c5edee48c4c8d705..61eaa74e60aa7d57d81527be1fb93557259cc0e1 100644
--- a/compiler/javatests/com/google/dart/compiler/type/TypeTestCase.java
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeTestCase.java
@@ -8,8 +8,19 @@ import com.google.dart.compiler.DartCompilationError;
import com.google.dart.compiler.DartCompilerListener;
import com.google.dart.compiler.ErrorCode;
import com.google.dart.compiler.ast.DartUnit;
+import com.google.dart.compiler.ast.DartBlock;
+import com.google.dart.compiler.ast.DartFunction;
+import com.google.dart.compiler.ast.DartIdentifier;
+import com.google.dart.compiler.ast.DartInitializer;
+import com.google.dart.compiler.ast.DartMethodDefinition;
+import com.google.dart.compiler.ast.DartParameter;
+import com.google.dart.compiler.ast.DartStatement;
+import com.google.dart.compiler.ast.DartTypeNode;
+import com.google.dart.compiler.ast.DartTypeParameter;
+import com.google.dart.compiler.ast.Modifiers;
import com.google.dart.compiler.resolver.ClassElement;
import com.google.dart.compiler.resolver.Elements;
+import com.google.dart.compiler.resolver.MethodElement;
import com.google.dart.compiler.resolver.TypeVariableElement;
import com.google.dart.compiler.testing.TestCompilerContext;
@@ -18,6 +29,7 @@ import junit.framework.TestCase;
import org.junit.Assert;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -35,7 +47,8 @@ abstract class TypeTestCase extends TestCase {
final ClassElement doubleElement = element("double", itype(number));
final ClassElement bool = element("bool", itype(object));
final ClassElement string = element("String", itype(object));
- final ClassElement list = element("List", itype(object), typeVar("E", itype(object)));
+ final ClassElement iterElement = element("Iterator", itype(object), typeVar("E", itype(object)));
+ final ClassElement list = makeListElement();
final ClassElement map = element("Map", itype(object),
typeVar("K", itype(object)), typeVar("V", itype(object)));
final ClassElement stackTrace = element("StackTrace", itype(object));
@@ -59,6 +72,27 @@ abstract class TypeTestCase extends TestCase {
abstract Types getTypes();
+ ClassElement makeListElement() {
+ final TypeVariable typeVar = typeVar("E", itype(object));
+ final ClassElement element = element("List", itype(object), typeVar);
+ DartTypeNode returnTypeNode = new DartTypeNode(new DartIdentifier("Iterator"),
+ Arrays.asList(new DartTypeNode(new DartIdentifier("E"))));
+
+ DartMethodDefinition iteratorMethod = DartMethodDefinition.create(
+ new DartIdentifier("iterator"), new DartFunction(Collections.<DartParameter>emptyList(),
+ new DartBlock(Collections.<DartStatement>emptyList()), returnTypeNode),
+ Modifiers.NONE,
+ Collections.<DartInitializer>emptyList(),
+ Collections.<DartTypeParameter>emptyList());
+ MethodElement iteratorMethodElement = Elements.methodFromMethodNode(iteratorMethod, element);
+ Type returnType = Types.interfaceType(iterElement, Arrays.asList(typeVar));
+ FunctionType functionType = ftype(function, returnType, Collections.<String,Type>emptyMap(),
+ null);
+ Elements.setType(iteratorMethodElement, functionType);
+ Elements.addMethod(element, iteratorMethodElement);
+ return element;
+ }
+
protected void setExpectedTypeErrorCount(int count) {
checkExpectedTypeErrorCount();
expectedTypeErrors = count;
« no previous file with comments | « compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698