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

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

Issue 13375005: Implement subtype for type variables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased Created 7 years, 8 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
« no previous file with comments | « no previous file | tests/compiler/dart2js/subtype_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ce0cdfa9e188103f6fd208eafc282bcef89bbd05..96e52c8b50205ba5600ad2e1577b70380d505922 100644
--- a/sdk/lib/_internal/compiler/implementation/dart_types.dart
+++ b/sdk/lib/_internal/compiler/implementation/dart_types.dart
@@ -1053,8 +1053,30 @@ class SubtypeVisitor extends DartTypeVisitor<bool, DartType> {
}
bool visitTypeVariableType(TypeVariableType t, DartType s) {
- if (s is !TypeVariableType) return false;
- return (identical(t.element, s.element));
+ // Identity check is handled in [isSubtype].
+ DartType bound = t.element.bound;
+ if (bound.element.isTypeVariable()) {
+ // The bound is potentially cyclic so we need to be extra careful.
+ Link<TypeVariableElement> seenTypeVariables =
+ const Link<TypeVariableElement>();
+ seenTypeVariables = seenTypeVariables.prepend(t.element);
+ while (bound.element.isTypeVariable()) {
+ TypeVariableElement element = bound.element;
+ if (identical(bound.element, s.element)) {
+ // [t] extends [s].
+ return true;
+ }
+ if (seenTypeVariables.contains(element)) {
+ // We have a cycle and have already checked all bounds in the cycle
+ // against [s] and can therefore conclude that [t] is not a subtype
+ // of [s].
+ return false;
+ }
+ seenTypeVariables = seenTypeVariables.prepend(element);
+ bound = element.bound;
+ }
+ }
+ return isSubtype(bound, s);
}
}
« no previous file with comments | « no previous file | tests/compiler/dart2js/subtype_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698