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

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

Issue 11442061: Issue 7271. If class has method call() with type F, class should be considered as subtype of functi… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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 | compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java » ('j') | 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 8ec7a882e4469c32437ab090e9b773c2fae015b1..021ec432079972abe10a3e3ba7c2c660ff7fe7db 100644
--- a/compiler/java/com/google/dart/compiler/type/Types.java
+++ b/compiler/java/com/google/dart/compiler/type/Types.java
@@ -24,6 +24,7 @@ import com.google.dart.compiler.resolver.FunctionAliasElement;
import com.google.dart.compiler.resolver.ResolutionErrorListener;
import com.google.dart.compiler.resolver.TypeVariableElement;
import com.google.dart.compiler.resolver.VariableElement;
+import com.google.dart.compiler.type.InterfaceType.Member;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
@@ -309,9 +310,15 @@ public class Types {
}
return true;
}
- if (t.getKind().equals(TypeKind.FUNCTION_ALIAS)) {
+ if (t.getKind() == TypeKind.FUNCTION_ALIAS) {
return isSubtypeOfFunction(asFunctionType((FunctionAliasType) t), asFunctionType(s));
}
+ // class has method call()
+ if (t.getKind() == TypeKind.INTERFACE) {
+ InterfaceType ti = (InterfaceType) t;
+ Member callMember = ti.lookupMember("call");
+ return callMember != null && isSubtype(callMember.getType(), asFunctionType(s));
+ }
return false;
}
@@ -349,9 +356,18 @@ public class Types {
return false;
}
+ // class "t" implements call() and "s" is Function
+ if (TypeKind.of(t) == TypeKind.INTERFACE && typeProvider != null
+ && s == typeProvider.getFunctionType()) {
+ InterfaceType ti = (InterfaceType) t;
+ if (ti.lookupMember("call") != null) {
+ return true;
+ }
+ }
+
// Try to cast "t" to "s".
final Type sup = asInstanceOf(t, s.getElement());
- if (TypeKind.of(sup).equals(TypeKind.INTERFACE)) {
+ if (TypeKind.of(sup) == TypeKind.INTERFACE) {
InterfaceType ti = (InterfaceType) sup;
assert ti.getElement().equals(s.getElement());
if (ti.isRaw() || s.isRaw()) {
@@ -520,6 +536,7 @@ public class Types {
InterfaceType ti = (InterfaceType) t;
ClassElement tElement = ti.getElement();
InterfaceType supertype = tElement.getSupertype();
+ // super type
if (supertype != null) {
InterfaceType result = checkedAsInstanceOf(asSupertype(ti, supertype), element,
variablesReferenced, checkedTypes);
@@ -527,6 +544,7 @@ public class Types {
return result;
}
}
+ // interfaces
for (InterfaceType intrface : tElement.getInterfaces()) {
InterfaceType result = checkedAsInstanceOf(asSupertype(ti, intrface), element,
variablesReferenced, checkedTypes);
@@ -534,6 +552,7 @@ public class Types {
return result;
}
}
+ // no
return null;
}
case FUNCTION: {
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698