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 1655b682dd477faa13aa0c93bcd9de9c2b55546f..acc340b3e8e658628e3093e6ddec291e4bc2714b 100644 |
--- a/compiler/java/com/google/dart/compiler/type/Types.java |
+++ b/compiler/java/com/google/dart/compiler/type/Types.java |
@@ -19,11 +19,13 @@ import com.google.dart.compiler.resolver.VariableElement; |
import java.util.ArrayList; |
import java.util.Collections; |
+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. |
@@ -257,6 +259,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: { |
@@ -267,13 +273,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; |
} |
@@ -287,7 +295,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; |
} |
@@ -295,7 +303,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(); |
mmendez
2012/01/31 19:30:51
Nit: should this be the bound of the type variable
|
+ } |
+ variablesReferenced.add(v); |
+ return checkedAsInstanceOf(bound, element, variablesReferenced); |
} |
default: |
return null; |