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

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

Issue 9186017: Fix crash in dartc when given cyclic type variable bounds. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated test Created 8 years, 11 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
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;

Powered by Google App Engine
This is Rietveld 408576698