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

Unified Diff: tests/compiler/dart2js/subtype_test.dart

Issue 12210013: Implement subtype for type variables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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: tests/compiler/dart2js/subtype_test.dart
diff --git a/tests/compiler/dart2js/subtype_test.dart b/tests/compiler/dart2js/subtype_test.dart
index daded9a14131f72bf84e6df65615fb07ccc16efe..5d5e3d6df7401aabd6d4289b73e8e188f4c6c439 100644
--- a/tests/compiler/dart2js/subtype_test.dart
+++ b/tests/compiler/dart2js/subtype_test.dart
@@ -11,6 +11,7 @@ import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
void main() {
testInterfaceSubtype();
+ testTypeVariableSubtype();
}
void testInterfaceSubtype() {
@@ -216,3 +217,96 @@ void testInterfaceSubtype() {
}
+void testTypeVariableSubtype() {
+ var env = new TypeEnvironment(r"""
+ class A<T, S extends Object, U extends int> {}
+ class B<T, S extends T, U extends S> {}
+ """);
+
+ void expect(bool value, DartType T, DartType S) {
+ print('$T <: $S');
+ Expect.equals(value, env.isSubtype(T, S), '$T <: $S');
+ }
+
+ DartType Object_ = env['Object'];
+ DartType num_ = env['num'];
+ DartType int_ = env['int'];
+ DartType dynamic_ = env['dynamic'];
+
+ InterfaceType A = env['A'];
+ DartType A_T = A.typeArguments.head;
+ DartType A_S = A.typeArguments.skip(1).head;
+ DartType A_U = A.typeArguments.skip(2).head;
+
+
+ InterfaceType B = env['B'];
+ DartType B_T = B.typeArguments.head;
+ DartType B_S = B.typeArguments.skip(1).head;
+ DartType B_U = B.typeArguments.skip(2).head;
+
+ expect(true, A_T, A_T);
+ expect(false, A_T, A_S);
+ expect(false, A_T, A_U);
+ expect(false, A_T, B_T);
+ expect(false, A_T, B_S);
+ expect(false, A_T, B_U);
+ expect(true, A_T, Object_);
+ expect(false, A_T, num_);
+ expect(false, A_T, int_);
+ expect(true, A_T, dynamic_);
+
+ expect(false, A_S, A_T);
+ expect(true, A_S, A_S);
+ expect(false, A_S, A_U);
+ expect(false, A_S, B_T);
+ expect(false, A_S, B_S);
+ expect(false, A_S, B_U);
+ expect(true, A_S, Object_);
+ expect(false, A_S, num_);
+ expect(false, A_S, int_);
+ expect(true, A_S, dynamic_);
+
+ expect(false, A_U, A_T);
+ expect(false, A_U, A_S);
+ expect(true, A_U, A_U);
+ expect(false, A_U, B_T);
+ expect(false, A_U, B_S);
+ expect(false, A_U, B_U);
+ expect(true, A_U, Object_);
+ expect(true, A_U, num_);
+ expect(true, A_U, int_);
+ expect(true, A_U, dynamic_);
+
+ expect(false, B_T, A_T);
+ expect(false, B_T, A_S);
+ expect(false, B_T, A_U);
+ expect(true, B_T, B_T);
+ expect(false, B_T, B_S);
+ expect(false, B_T, B_U);
+ expect(true, B_T, Object_);
+ expect(false, B_T, num_);
+ expect(false, B_T, int_);
+ expect(true, B_T, dynamic_);
+
+ expect(false, B_S, A_T);
+ expect(false, B_S, A_S);
+ expect(false, B_S, A_U);
+ expect(true, B_S, B_T);
+ expect(true, B_S, B_S);
+ expect(false, B_S, B_U);
+ expect(true, B_S, Object_);
+ expect(false, B_S, num_);
+ expect(false, B_S, int_);
+ expect(true, B_S, dynamic_);
+
+ expect(false, B_U, A_T);
+ expect(false, B_U, A_S);
+ expect(false, B_U, A_U);
+ expect(true, B_U, B_T);
+ expect(true, B_U, B_S);
+ expect(true, B_U, B_U);
+ expect(true, B_U, Object_);
+ expect(false, B_U, num_);
+ expect(false, B_U, int_);
+ expect(true, B_U, dynamic_);
+}

Powered by Google App Engine
This is Rietveld 408576698