| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, 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 // VMOptions=--checked | |
| 5 // Dart test program testing generic type allocations and generic type tests. | |
| 6 import "package:expect/expect.dart"; | |
| 7 | |
| 8 class A { | |
| 9 const A(); | |
| 10 } | |
| 11 | |
| 12 class AA extends A { | |
| 13 const AA(); | |
| 14 } | |
| 15 | |
| 16 class AX { | |
| 17 const AX(); | |
| 18 } | |
| 19 | |
| 20 class B<T extends A> { | |
| 21 final A a_; | |
| 22 final T t_; | |
| 23 const B(T t) | |
| 24 : a_ = t, | |
| 25 t_ = t; | |
| 26 isT(x) { | |
| 27 return x is T; | |
| 28 } | |
| 29 } | |
| 30 | |
| 31 class C<T> { | |
| 32 B<T> b_; | |
| 33 C(T t) : b_ = new B<T>(t) {} | |
| 34 } | |
| 35 | |
| 36 class D { | |
| 37 C<AA> caa_; | |
| 38 D() : caa_ = new C<AA>(const AA()) {} | |
| 39 } | |
| 40 | |
| 41 class E { | |
| 42 C<AX> cax_; | |
| 43 E() : cax_ = new C<AX>(const AX()) {} | |
| 44 } | |
| 45 | |
| 46 class GenericTest { | |
| 47 static test() { | |
| 48 int result = 0; | |
| 49 D d = new D(); | |
| 50 Expect.equals(true, d.caa_.b_ is B<AA>); | |
| 51 Expect.equals(true, d.caa_.b_.isT(const AA())); | |
| 52 C c = new C(const AA()); // c is of raw type C, T in C<T> is dynamic. | |
| 53 Expect.equals(true, c.b_ is B); | |
| 54 Expect.equals(true, c.b_ is B<AA>); | |
| 55 Expect.equals(true, c.b_.isT(const AA())); | |
| 56 Expect.equals(true, c.b_.isT(const AX())); | |
| 57 try { | |
| 58 E e = new E(); // Throws a type error, if type checks are enabled. | |
| 59 } on TypeError catch (error) { | |
| 60 result = 1; | |
| 61 } | |
| 62 return result; | |
| 63 } | |
| 64 | |
| 65 static testMain() { | |
| 66 Expect.equals(1, test()); | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 main() { | |
| 71 GenericTest.testMain(); | |
| 72 } | |
| OLD | NEW |