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

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

Issue 10535027: Issue 3221. Use upper bound type of then/else expressions for conditional (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 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 f730a334e81ba66c5eeb1fb3f492bffe58a608e3..163e862baf401368ac7a14011c9c68218c1b73d6 100644
--- a/compiler/java/com/google/dart/compiler/type/Types.java
+++ b/compiler/java/com/google/dart/compiler/type/Types.java
@@ -5,6 +5,7 @@
package com.google.dart.compiler.type;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.Lists;
import com.google.common.collect.MapMaker;
import com.google.dart.compiler.ast.DartNewExpression;
import com.google.dart.compiler.ast.DartNode;
@@ -48,9 +49,37 @@ public class Types {
} else if (isSubtype(s, t)) {
return t;
} else {
- // TODO(karlklose) Return the intersection of the implemented interfaces.
- return typeProvider.getDynamicType();
+ List<InterfaceType> tTypes = getSuperTypes(t);
+ List<InterfaceType> sTypes = getSuperTypes(s);
+ for (InterfaceType tType : tTypes) {
+ if (sTypes.contains(tType)) {
+ return tType;
+ }
+ }
+ return typeProvider.getObjectType();
+ }
+ }
+
+ /**
+ * @return list of the super-types (if class type given) or super-interfaces (if interface type
+ * given) from most specific to least specific.
+ */
+ private static List<InterfaceType> getSuperTypes(Type type) {
+ List<InterfaceType> types = Lists.newArrayList();
+ if (type instanceof InterfaceType) {
+ InterfaceType interfaceType = (InterfaceType) type;
+ if (interfaceType.getElement().isInterface()) {
+ types.add(interfaceType);
+ for (InterfaceType intf : interfaceType.getElement().getInterfaces()) {
+ types.addAll(getSuperTypes(intf));
+ }
+ } else {
+ for (InterfaceType st = interfaceType; st != null; st = st.getElement().getSupertype()) {
+ types.add(st);
+ }
+ }
}
+ return types;
}
/**

Powered by Google App Engine
This is Rietveld 408576698