Index: compiler/java/com/google/dart/compiler/type/Types.java |
diff --git a/compiler/java/com/google/dart/compiler/type/Types.java b/compiler/java/com/google/dart/compiler/type/Types.java |
index d882aee5c96147afe78158230544cb2ac78f60a0..ebe91a742acdcb164af594a14f4762dfef797f29 100644 |
--- a/compiler/java/com/google/dart/compiler/type/Types.java |
+++ b/compiler/java/com/google/dart/compiler/type/Types.java |
@@ -18,11 +18,13 @@ import com.google.dart.compiler.resolver.TypeVariableElement; |
import com.google.dart.compiler.resolver.VariableElement; |
import java.util.ArrayList; |
+import java.util.HashSet; |
import java.util.Iterator; |
import java.util.LinkedHashMap; |
import java.util.List; |
import java.util.Map; |
import java.util.Map.Entry; |
+import java.util.Set; |
/** |
* Utility class for types. |
@@ -256,6 +258,10 @@ public class Types { |
*/ |
@VisibleForTesting |
public InterfaceType asInstanceOf(Type t, ClassElement element) { |
+ return checkedAsInstanceOf(t, element, new HashSet<TypeVariable>()); |
+ } |
+ |
+ private InterfaceType checkedAsInstanceOf(Type t, ClassElement element, Set<TypeVariable> variablesReferenced) { |
switch (TypeKind.of(t)) { |
case FUNCTION_ALIAS: |
case INTERFACE: { |
@@ -266,13 +272,15 @@ public class Types { |
ClassElement tElement = ti.getElement(); |
InterfaceType supertype = tElement.getSupertype(); |
if (supertype != null) { |
- InterfaceType result = asInstanceOf(asSupertype(ti, supertype), element); |
+ InterfaceType result = checkedAsInstanceOf(asSupertype(ti, supertype), element, |
+ variablesReferenced); |
if (result != null) { |
return result; |
} |
} |
for (InterfaceType intrface : tElement.getInterfaces()) { |
- InterfaceType result = asInstanceOf(asSupertype(ti, intrface), element); |
+ InterfaceType result = checkedAsInstanceOf(asSupertype(ti, intrface), element, |
+ variablesReferenced); |
if (result != null) { |
return result; |
} |
@@ -286,7 +294,7 @@ public class Types { |
// e should be the interface Function in the core library. See the |
// documentation comment on FunctionType. |
InterfaceType ti = (InterfaceType) e.getType(); |
- return asInstanceOf(ti, element); |
+ return checkedAsInstanceOf(ti, element, variablesReferenced); |
default: |
return null; |
} |
@@ -294,7 +302,11 @@ public class Types { |
case VARIABLE: { |
TypeVariable v = (TypeVariable) t; |
Type bound = v.getTypeVariableElement().getBound(); |
- return asInstanceOf(bound, element); |
+ if (variablesReferenced.contains(v)) { |
+ return typeProvider.getObjectType(); |
+ } |
+ variablesReferenced.add(v); |
+ return checkedAsInstanceOf(bound, element, variablesReferenced); |
} |
default: |
return null; |