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

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

Issue 11366062: Use union type parts when check if type is subtype. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 32897f84eac2b1434beb3e729b267a3e36c7fb2f..d825e85c2f0cb06e55b11905ea6981f9ceb5ae13 100644
--- a/compiler/java/com/google/dart/compiler/type/Types.java
+++ b/compiler/java/com/google/dart/compiler/type/Types.java
@@ -185,7 +185,7 @@ public class Types {
* @return the {@link InterfaceType} which is union of given ones.
*/
public InterfaceType unionTypes(List<InterfaceType> types) {
- return new InterfaceTypeUnion(types);
+ return new InterfaceTypeUnionImplementation(types);
}
/**
@@ -338,8 +338,19 @@ public class Types {
}
private boolean isSubtypeOfInterface(Type t, InterfaceType s) {
- final Type sup = asInstanceOf(t, s.getElement());
+ // Special handling for union.
+ if (t instanceof InterfaceTypeUnion) {
+ InterfaceTypeUnion tUnion = (InterfaceTypeUnion) t;
+ for (InterfaceType unionPart : tUnion.getTypes()) {
+ if (isSubtype(unionPart, s)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ // Try to cast "t" to "s".
+ final Type sup = asInstanceOf(t, s.getElement());
if (TypeKind.of(sup).equals(TypeKind.INTERFACE)) {
InterfaceType ti = (InterfaceType) sup;
assert ti.getElement().equals(s.getElement());
@@ -354,7 +365,7 @@ public class Types {
/**
* Implement the Dart function subtype rule. Unlike the classic arrow rule (return type is
- * covariant, and paramter types are contravariant), in Dart they must just be assignable.
+ * covariant, and parameter types are contravariant), in Dart they must just be assignable.
*/
private boolean isSubtypeOfFunction(FunctionType t, FunctionType s) {
if (s.getKind() == TypeKind.DYNAMIC || t.getKind() == TypeKind.DYNAMIC) {

Powered by Google App Engine
This is Rietveld 408576698