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

Unified Diff: compiler/java/com/google/dart/compiler/type/Types.java

Issue 10140009: Issue 2702. Prevent infinite recursion (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 05601ecd8281d49975ed3fea8e275ccd74e4706e..93e5ec862da2e7d315563c29859529624c782944 100644
--- a/compiler/java/com/google/dart/compiler/type/Types.java
+++ b/compiler/java/com/google/dart/compiler/type/Types.java
@@ -259,10 +259,17 @@ public class Types {
*/
@VisibleForTesting
public InterfaceType asInstanceOf(Type t, ClassElement element) {
- return checkedAsInstanceOf(t, element, new HashSet<TypeVariable>());
+ return checkedAsInstanceOf(t, element, new HashSet<TypeVariable>(), new HashSet<Type>());
}
- private InterfaceType checkedAsInstanceOf(Type t, ClassElement element, Set<TypeVariable> variablesReferenced) {
+ private InterfaceType checkedAsInstanceOf(Type t, ClassElement element,
+ Set<TypeVariable> variablesReferenced, Set<Type> checkedTypes) {
+ // check for recursion
+ if (checkedTypes.contains(t)) {
+ return null;
+ }
+ checkedTypes.add(t);
+ // check current Type
switch (TypeKind.of(t)) {
case FUNCTION_ALIAS:
case INTERFACE: {
@@ -274,14 +281,14 @@ public class Types {
InterfaceType supertype = tElement.getSupertype();
if (supertype != null) {
InterfaceType result = checkedAsInstanceOf(asSupertype(ti, supertype), element,
- variablesReferenced);
+ variablesReferenced, checkedTypes);
if (result != null) {
return result;
}
}
for (InterfaceType intrface : tElement.getInterfaces()) {
InterfaceType result = checkedAsInstanceOf(asSupertype(ti, intrface), element,
- variablesReferenced);
+ variablesReferenced, checkedTypes);
if (result != null) {
return result;
}
@@ -295,7 +302,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 checkedAsInstanceOf(ti, element, variablesReferenced);
+ return checkedAsInstanceOf(ti, element, variablesReferenced, checkedTypes);
default:
return null;
}
@@ -311,7 +318,7 @@ public class Types {
return typeProvider.getObjectType();
}
variablesReferenced.add(v);
- return checkedAsInstanceOf(bound, element, variablesReferenced);
+ return checkedAsInstanceOf(bound, element, variablesReferenced, checkedTypes);
}
default:
return null;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698