| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library subtype_test; | |
| 6 | |
| 7 import 'type_test_helper.dart'; | |
| 8 import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart'; | |
| 9 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t" | |
| 10 show Element, ClassElement; | |
| 11 | |
| 12 void main() { | |
| 13 testInterfaceSubtype(); | |
| 14 } | |
| 15 | |
| 16 void testInterfaceSubtype() { | |
| 17 var env = new TypeEnvironment(r""" | |
| 18 class A<T> {} | |
| 19 class B<T1,T2> extends A<T1> {} | |
| 20 // TODO(johnniwinther): Inheritance with different type arguments is | |
| 21 // currently not supported by the implementation. | |
| 22 class C<T1,T2> extends B<T2,T1> /*implements A<A<T1>>*/ {} | |
| 23 """); | |
| 24 | |
| 25 void expect(bool value, DartType T, DartType S) { | |
| 26 Expect.equals(value, env.isSubtype(T, S), '$T <: $S'); | |
| 27 } | |
| 28 | |
| 29 ClassElement A = env.getElement('A'); | |
| 30 ClassElement B = env.getElement('B'); | |
| 31 ClassElement C = env.getElement('C'); | |
| 32 DartType Object_ = env['Object']; | |
| 33 DartType num_ = env['num']; | |
| 34 DartType int_ = env['int']; | |
| 35 DartType String_ = env['String']; | |
| 36 DartType dynamic_ = env['dynamic']; | |
| 37 | |
| 38 expect(true, Object_, Object_); | |
| 39 expect(true, num_, Object_); | |
| 40 expect(true, int_, Object_); | |
| 41 expect(true, String_, Object_); | |
| 42 expect(true, dynamic_, Object_); | |
| 43 | |
| 44 expect(false, Object_, num_); | |
| 45 expect(true, num_, num_); | |
| 46 expect(true, int_, num_); | |
| 47 expect(false, String_, num_); | |
| 48 expect(true, dynamic_, num_); | |
| 49 | |
| 50 expect(false, Object_, int_); | |
| 51 expect(false, num_, int_); | |
| 52 expect(true, int_, int_); | |
| 53 expect(false, String_, int_); | |
| 54 expect(true, dynamic_, int_); | |
| 55 | |
| 56 expect(false, Object_, String_); | |
| 57 expect(false, num_, String_); | |
| 58 expect(false, int_, String_); | |
| 59 expect(true, String_, String_); | |
| 60 expect(true, dynamic_, String_); | |
| 61 | |
| 62 expect(true, Object_, dynamic_); | |
| 63 expect(true, num_, dynamic_); | |
| 64 expect(true, int_, dynamic_); | |
| 65 expect(true, String_, dynamic_); | |
| 66 expect(true, dynamic_, dynamic_); | |
| 67 | |
| 68 DartType A_Object = instantiate(A, [Object_]); | |
| 69 DartType A_num = instantiate(A, [num_]); | |
| 70 DartType A_int = instantiate(A, [int_]); | |
| 71 DartType A_String = instantiate(A, [String_]); | |
| 72 DartType A_dynamic = instantiate(A, [dynamic_]); | |
| 73 | |
| 74 expect(true, A_Object, Object_); | |
| 75 expect(false, A_Object, num_); | |
| 76 expect(false, A_Object, int_); | |
| 77 expect(false, A_Object, String_); | |
| 78 expect(true, A_Object, dynamic_); | |
| 79 | |
| 80 expect(true, A_Object, A_Object); | |
| 81 expect(true, A_num, A_Object); | |
| 82 expect(true, A_int, A_Object); | |
| 83 expect(true, A_String, A_Object); | |
| 84 expect(true, A_dynamic, A_Object); | |
| 85 | |
| 86 expect(false, A_Object, A_num); | |
| 87 expect(true, A_num, A_num); | |
| 88 expect(true, A_int, A_num); | |
| 89 expect(false, A_String, A_num); | |
| 90 expect(true, A_dynamic, A_num); | |
| 91 | |
| 92 expect(false, A_Object, A_int); | |
| 93 expect(false, A_num, A_int); | |
| 94 expect(true, A_int, A_int); | |
| 95 expect(false, A_String, A_int); | |
| 96 expect(true, A_dynamic, A_int); | |
| 97 | |
| 98 expect(false, A_Object, A_String); | |
| 99 expect(false, A_num, A_String); | |
| 100 expect(false, A_int, A_String); | |
| 101 expect(true, A_String, A_String); | |
| 102 expect(true, A_dynamic, A_String); | |
| 103 | |
| 104 expect(true, A_Object, A_dynamic); | |
| 105 expect(true, A_num, A_dynamic); | |
| 106 expect(true, A_int, A_dynamic); | |
| 107 expect(true, A_String, A_dynamic); | |
| 108 expect(true, A_dynamic, A_dynamic); | |
| 109 | |
| 110 DartType B_Object_Object = instantiate(B, [Object_, Object_]); | |
| 111 DartType B_num_num = instantiate(B, [num_, num_]); | |
| 112 DartType B_int_num = instantiate(B, [int_, num_]); | |
| 113 DartType B_dynamic_dynamic = instantiate(B, [dynamic_, dynamic_]); | |
| 114 DartType B_String_dynamic = instantiate(B, [String_, dynamic_]); | |
| 115 | |
| 116 expect(true, B_Object_Object, Object_); | |
| 117 expect(true, B_Object_Object, A_Object); | |
| 118 expect(false, B_Object_Object, A_num); | |
| 119 expect(false, B_Object_Object, A_int); | |
| 120 expect(false, B_Object_Object, A_String); | |
| 121 expect(true, B_Object_Object, A_dynamic); | |
| 122 | |
| 123 expect(true, B_num_num, Object_); | |
| 124 expect(true, B_num_num, A_Object); | |
| 125 expect(true, B_num_num, A_num); | |
| 126 expect(false, B_num_num, A_int); | |
| 127 expect(false, B_num_num, A_String); | |
| 128 expect(true, B_num_num, A_dynamic); | |
| 129 | |
| 130 expect(true, B_int_num, Object_); | |
| 131 expect(true, B_int_num, A_Object); | |
| 132 expect(true, B_int_num, A_num); | |
| 133 expect(true, B_int_num, A_int); | |
| 134 expect(false, B_int_num, A_String); | |
| 135 expect(true, B_int_num, A_dynamic); | |
| 136 | |
| 137 expect(true, B_dynamic_dynamic, Object_); | |
| 138 expect(true, B_dynamic_dynamic, A_Object); | |
| 139 expect(true, B_dynamic_dynamic, A_num); | |
| 140 expect(true, B_dynamic_dynamic, A_int); | |
| 141 expect(true, B_dynamic_dynamic, A_String); | |
| 142 expect(true, B_dynamic_dynamic, A_dynamic); | |
| 143 | |
| 144 expect(true, B_String_dynamic, Object_); | |
| 145 expect(true, B_String_dynamic, A_Object); | |
| 146 expect(false, B_String_dynamic, A_num); | |
| 147 expect(false, B_String_dynamic, A_int); | |
| 148 expect(true, B_String_dynamic, A_String); | |
| 149 expect(true, B_String_dynamic, A_dynamic); | |
| 150 | |
| 151 expect(true, B_Object_Object, B_Object_Object); | |
| 152 expect(true, B_num_num, B_Object_Object); | |
| 153 expect(true, B_int_num, B_Object_Object); | |
| 154 expect(true, B_dynamic_dynamic, B_Object_Object); | |
| 155 expect(true, B_String_dynamic, B_Object_Object); | |
| 156 | |
| 157 expect(false, B_Object_Object, B_num_num); | |
| 158 expect(true, B_num_num, B_num_num); | |
| 159 expect(true, B_int_num, B_num_num); | |
| 160 expect(true, B_dynamic_dynamic, B_num_num); | |
| 161 expect(false, B_String_dynamic, B_num_num); | |
| 162 | |
| 163 expect(false, B_Object_Object, B_int_num); | |
| 164 expect(false, B_num_num, B_int_num); | |
| 165 expect(true, B_int_num, B_int_num); | |
| 166 expect(true, B_dynamic_dynamic, B_int_num); | |
| 167 expect(false, B_String_dynamic, B_int_num); | |
| 168 | |
| 169 expect(true, B_Object_Object, B_dynamic_dynamic); | |
| 170 expect(true, B_num_num, B_dynamic_dynamic); | |
| 171 expect(true, B_int_num, B_dynamic_dynamic); | |
| 172 expect(true, B_dynamic_dynamic, B_dynamic_dynamic); | |
| 173 expect(true, B_String_dynamic, B_dynamic_dynamic); | |
| 174 | |
| 175 expect(false, B_Object_Object, B_String_dynamic); | |
| 176 expect(false, B_num_num, B_String_dynamic); | |
| 177 expect(false, B_int_num, B_String_dynamic); | |
| 178 expect(true, B_dynamic_dynamic, B_String_dynamic); | |
| 179 expect(true, B_String_dynamic, B_String_dynamic); | |
| 180 | |
| 181 DartType C_Object_Object = instantiate(C, [Object_, Object_]); | |
| 182 DartType C_num_num = instantiate(C, [num_, num_]); | |
| 183 DartType C_int_String = instantiate(C, [int_, String_]); | |
| 184 DartType C_dynamic_dynamic = instantiate(C, [dynamic_, dynamic_]); | |
| 185 | |
| 186 expect(true, C_Object_Object, B_Object_Object); | |
| 187 expect(false, C_Object_Object, B_num_num); | |
| 188 expect(false, C_Object_Object, B_int_num); | |
| 189 expect(true, C_Object_Object, B_dynamic_dynamic); | |
| 190 expect(false, C_Object_Object, B_String_dynamic); | |
| 191 | |
| 192 expect(true, C_num_num, B_Object_Object); | |
| 193 expect(true, C_num_num, B_num_num); | |
| 194 expect(false, C_num_num, B_int_num); | |
| 195 expect(true, C_num_num, B_dynamic_dynamic); | |
| 196 expect(false, C_num_num, B_String_dynamic); | |
| 197 | |
| 198 expect(true, C_int_String, B_Object_Object); | |
| 199 expect(false, C_int_String, B_num_num); | |
| 200 expect(false, C_int_String, B_int_num); | |
| 201 expect(true, C_int_String, B_dynamic_dynamic); | |
| 202 expect(true, C_int_String, B_String_dynamic); | |
| 203 | |
| 204 expect(true, C_dynamic_dynamic, B_Object_Object); | |
| 205 expect(true, C_dynamic_dynamic, B_num_num); | |
| 206 expect(true, C_dynamic_dynamic, B_int_num); | |
| 207 expect(true, C_dynamic_dynamic, B_dynamic_dynamic); | |
| 208 expect(true, C_dynamic_dynamic, B_String_dynamic); | |
| 209 | |
| 210 expect(false, C_int_String, A_int); | |
| 211 expect(true, C_int_String, A_String); | |
| 212 // TODO(johnniwinther): Inheritance with different type arguments is | |
| 213 // currently not supported by the implementation. | |
| 214 //expect(true, C_int_String, instantiate(A, [A_int])); | |
| 215 expect(false, C_int_String, instantiate(A, [A_String])); | |
| 216 } | |
| 217 | |
| 218 | |
| OLD | NEW |