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

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

Issue 48383003: Support checking of malbounded types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 b6d3234f3258d9d6ba55e8a303bb6028029209d4..3c7ef85ffdb60db379ab78dc827a879dfb32712b 100644
--- a/sdk/lib/_internal/compiler/implementation/dart_types.dart
+++ b/sdk/lib/_internal/compiler/implementation/dart_types.dart
@@ -1207,6 +1207,16 @@ class SubtypeVisitor extends MoreSpecificVisitor {
}
}
+/**
+ * Callback used to check whether the [typeArgument] of [type] is a valid
+ * substitute for the bound of [typeVariable]. [bound] holds the bound against
+ * which [typeArgument] should be checked.
+ */
+typedef void CheckTypeVariableBound(GenericType type,
+ DartType typeArgument,
+ TypeVariableType typeVariable,
+ DartType bound);
+
class Types {
final Compiler compiler;
// TODO(karlklose): should we have a class Void?
@@ -1250,6 +1260,16 @@ class Types {
return subtypeVisitor.isAssignable(r, s);
}
+ static const int IS_SUBTYPE = 1;
+ static const int MAYBE_SUBTYPE = 0;
+ static const int NOT_SUBTYPE = -1;
+
+ int isMaybeSubtype(DartType t, DartType s) {
karlklose 2013/10/30 09:47:43 The name indicates that this is a predicate. How a
Johnni Winther 2013/10/30 11:19:42 Done.
+ // TODO(johnniwinther): Compute this directly in [isPotentialSubtype].
+ if (isSubtype(t, s)) return IS_SUBTYPE;
+ return isPotentialSubtype(t, s) ? MAYBE_SUBTYPE : NOT_SUBTYPE;
+ }
+
bool isPotentialSubtype(DartType t, DartType s) {
// TODO(johnniwinther): Return a set of variable points in the positive
// cases.
@@ -1257,6 +1277,27 @@ class Types {
}
/**
+ * Checks the type arguments of [type] against the type variable bounds
+ * declared on [element]. Calls [checkTypeVariableBound] on each type
+ * argument and bound.
+ */
+ void checkTypeVariableBounds(GenericType type,
+ CheckTypeVariableBound checkTypeVariableBound) {
+ TypeDeclarationElement element = type.element;
+ Link<DartType> typeArguments = type.typeArguments;
+ Link<DartType> typeVariables = element.typeVariables;
+ while (!typeVariables.isEmpty && !typeArguments.isEmpty) {
+ TypeVariableType typeVariable = typeVariables.head;
+ DartType bound = typeVariable.element.bound.subst(
+ type.typeArguments, element.typeVariables);
+ DartType typeArgument = typeArguments.head;
+ checkTypeVariableBound(type, typeArgument, typeVariable, bound);
+ typeVariables = typeVariables.tail;
+ typeArguments = typeArguments.tail;
+ }
+ }
karlklose 2013/10/30 09:47:43 assert that both links are empty.
Johnni Winther 2013/10/30 11:19:42 Done.
+
+ /**
* Helper method for performing substitution of a linked list of types.
*
* If no types are changed by the substitution, the [types] is returned

Powered by Google App Engine
This is Rietveld 408576698