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

Unified Diff: sdk/lib/_internal/compiler/implementation/dart_types.dart

Issue 12334070: Support runtime check of function types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: New check encoding Created 7 years, 9 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: sdk/lib/_internal/compiler/implementation/dart_types.dart
diff --git a/sdk/lib/_internal/compiler/implementation/dart_types.dart b/sdk/lib/_internal/compiler/implementation/dart_types.dart
index 5f00a6239398959059aec7c69a12f529a4a0d9a7..b0a900246a95a1a9d68401c44d893518bf04344a 100644
--- a/sdk/lib/_internal/compiler/implementation/dart_types.dart
+++ b/sdk/lib/_internal/compiler/implementation/dart_types.dart
@@ -864,6 +864,8 @@ class Member {
}
abstract class DartTypeVisitor<R, A> {
+ const DartTypeVisitor();
+
R visitType(DartType type, A argument);
R visitVoidType(VoidType type, A argument) =>
@@ -1044,6 +1046,7 @@ class Types {
final VoidType voidType;
final DynamicType dynamicType;
final SubtypeVisitor subtypeVisitor;
+ final PotentialSubtypeVisitor potentialSubtypeVisitor;
factory Types(Compiler compiler, ClassElement dynamicElement) {
LibraryElement library = new LibraryElementX(new Script(null, null));
@@ -1052,11 +1055,15 @@ class Types {
dynamicElement.rawType = dynamicElement.thisType = dynamicType;
SubtypeVisitor subtypeVisitor =
new SubtypeVisitor(compiler, dynamicType, voidType);
- return new Types.internal(compiler, voidType, dynamicType, subtypeVisitor);
+ PotentialSubtypeVisitor potentialSubtypeVisitor =
+ new PotentialSubtypeVisitor(compiler, dynamicType, voidType);
+
+ return new Types.internal(compiler, voidType, dynamicType,
+ subtypeVisitor, potentialSubtypeVisitor);
}
Types.internal(this.compiler, this.voidType, this.dynamicType,
- this.subtypeVisitor);
+ this.subtypeVisitor, this.potentialSubtypeVisitor);
/** Returns true if t is a subtype of s */
bool isSubtype(DartType t, DartType s) {
@@ -1067,6 +1074,11 @@ class Types {
return subtypeVisitor.isAssignable(r, s);
}
+ bool isPotentialSubtype(DartType t, DartType s) {
+ // TODO(johnniwinther): Return a set of variable points in the positive
+ // cases.
+ return potentialSubtypeVisitor.isSubtype(t, s);
+ }
/**
* Helper method for performing substitution of a linked list of types.
@@ -1121,3 +1133,18 @@ class Types {
return typeVariable.element.enclosingElement;
}
}
+
+class PotentialSubtypeVisitor extends SubtypeVisitor {
+ PotentialSubtypeVisitor(Compiler compiler,
+ DynamicType dynamicType,
+ VoidType voidType)
+ : super(compiler, dynamicType, voidType);
+
+
+ bool isSubtype(DartType t, DartType s) {
+ if (t is TypeVariableType || s is TypeVariableType) {
+ return true;
+ }
+ return super.isSubtype(t, s);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698