| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library subtype_test; | 5 library subtype_test; |
| 6 | 6 |
| 7 import 'type_test_helper.dart'; | 7 import 'type_test_helper.dart'; |
| 8 import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart'; | 8 import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart'; |
| 9 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t" | 9 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t" |
| 10 show Element, ClassElement; | 10 show Element, ClassElement; |
| 11 | 11 |
| 12 void main() { | 12 void main() { |
| 13 testInterfaceSubtype(); | 13 testInterfaceSubtype(); |
| 14 testTypeVariableSubtype(); |
| 14 } | 15 } |
| 15 | 16 |
| 16 void testInterfaceSubtype() { | 17 void testInterfaceSubtype() { |
| 17 var env = new TypeEnvironment(r""" | 18 var env = new TypeEnvironment(r""" |
| 18 class A<T> {} | 19 class A<T> {} |
| 19 class B<T1,T2> extends A<T1> {} | 20 class B<T1,T2> extends A<T1> {} |
| 20 // TODO(johnniwinther): Inheritance with different type arguments is | 21 // TODO(johnniwinther): Inheritance with different type arguments is |
| 21 // currently not supported by the implementation. | 22 // currently not supported by the implementation. |
| 22 class C<T1,T2> extends B<T2,T1> /*implements A<A<T1>>*/ {} | 23 class C<T1,T2> extends B<T2,T1> /*implements A<A<T1>>*/ {} |
| 23 """); | 24 """); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 210 |
| 210 expect(false, C_int_String, A_int); | 211 expect(false, C_int_String, A_int); |
| 211 expect(true, C_int_String, A_String); | 212 expect(true, C_int_String, A_String); |
| 212 // TODO(johnniwinther): Inheritance with different type arguments is | 213 // TODO(johnniwinther): Inheritance with different type arguments is |
| 213 // currently not supported by the implementation. | 214 // currently not supported by the implementation. |
| 214 //expect(true, C_int_String, instantiate(A, [A_int])); | 215 //expect(true, C_int_String, instantiate(A, [A_int])); |
| 215 expect(false, C_int_String, instantiate(A, [A_String])); | 216 expect(false, C_int_String, instantiate(A, [A_String])); |
| 216 } | 217 } |
| 217 | 218 |
| 218 | 219 |
| 220 void testTypeVariableSubtype() { |
| 221 var env = new TypeEnvironment(r""" |
| 222 class A<T, S extends Object, U extends int> {} |
| 223 class B<T, S extends T, U extends S> {} |
| 224 """); |
| 225 |
| 226 void expect(bool value, DartType T, DartType S) { |
| 227 print('$T <: $S'); |
| 228 Expect.equals(value, env.isSubtype(T, S), '$T <: $S'); |
| 229 } |
| 230 |
| 231 DartType Object_ = env['Object']; |
| 232 DartType num_ = env['num']; |
| 233 DartType int_ = env['int']; |
| 234 DartType dynamic_ = env['dynamic']; |
| 235 |
| 236 InterfaceType A = env['A']; |
| 237 DartType A_T = A.typeArguments.head; |
| 238 DartType A_S = A.typeArguments.skip(1).head; |
| 239 DartType A_U = A.typeArguments.skip(2).head; |
| 240 |
| 241 |
| 242 InterfaceType B = env['B']; |
| 243 DartType B_T = B.typeArguments.head; |
| 244 DartType B_S = B.typeArguments.skip(1).head; |
| 245 DartType B_U = B.typeArguments.skip(2).head; |
| 246 |
| 247 expect(true, A_T, A_T); |
| 248 expect(false, A_T, A_S); |
| 249 expect(false, A_T, A_U); |
| 250 expect(false, A_T, B_T); |
| 251 expect(false, A_T, B_S); |
| 252 expect(false, A_T, B_U); |
| 253 expect(true, A_T, Object_); |
| 254 expect(false, A_T, num_); |
| 255 expect(false, A_T, int_); |
| 256 expect(true, A_T, dynamic_); |
| 257 |
| 258 expect(false, A_S, A_T); |
| 259 expect(true, A_S, A_S); |
| 260 expect(false, A_S, A_U); |
| 261 expect(false, A_S, B_T); |
| 262 expect(false, A_S, B_S); |
| 263 expect(false, A_S, B_U); |
| 264 expect(true, A_S, Object_); |
| 265 expect(false, A_S, num_); |
| 266 expect(false, A_S, int_); |
| 267 expect(true, A_S, dynamic_); |
| 268 |
| 269 expect(false, A_U, A_T); |
| 270 expect(false, A_U, A_S); |
| 271 expect(true, A_U, A_U); |
| 272 expect(false, A_U, B_T); |
| 273 expect(false, A_U, B_S); |
| 274 expect(false, A_U, B_U); |
| 275 expect(true, A_U, Object_); |
| 276 expect(true, A_U, num_); |
| 277 expect(true, A_U, int_); |
| 278 expect(true, A_U, dynamic_); |
| 279 |
| 280 expect(false, B_T, A_T); |
| 281 expect(false, B_T, A_S); |
| 282 expect(false, B_T, A_U); |
| 283 expect(true, B_T, B_T); |
| 284 expect(false, B_T, B_S); |
| 285 expect(false, B_T, B_U); |
| 286 expect(true, B_T, Object_); |
| 287 expect(false, B_T, num_); |
| 288 expect(false, B_T, int_); |
| 289 expect(true, B_T, dynamic_); |
| 290 |
| 291 expect(false, B_S, A_T); |
| 292 expect(false, B_S, A_S); |
| 293 expect(false, B_S, A_U); |
| 294 expect(true, B_S, B_T); |
| 295 expect(true, B_S, B_S); |
| 296 expect(false, B_S, B_U); |
| 297 expect(true, B_S, Object_); |
| 298 expect(false, B_S, num_); |
| 299 expect(false, B_S, int_); |
| 300 expect(true, B_S, dynamic_); |
| 301 |
| 302 expect(false, B_U, A_T); |
| 303 expect(false, B_U, A_S); |
| 304 expect(false, B_U, A_U); |
| 305 expect(true, B_U, B_T); |
| 306 expect(true, B_U, B_S); |
| 307 expect(true, B_U, B_U); |
| 308 expect(true, B_U, Object_); |
| 309 expect(false, B_U, num_); |
| 310 expect(false, B_U, int_); |
| 311 expect(true, B_U, dynamic_); |
| 312 } |
| OLD | NEW |