OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017, 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 // Test that generic methods that have bounds on type parameters can be |
| 6 // overridden, and that type propagation can be used in such methods. |
| 7 |
| 8 library generic_methods_overriding_type_propagation_test; |
| 9 |
| 10 import "test_base.dart"; |
| 11 |
| 12 class X {} |
| 13 |
| 14 class Y extends X {} |
| 15 |
| 16 class Z extends Y {} |
| 17 |
| 18 class C { |
| 19 String fun<T extends Y>(T t) => "C"; |
| 20 } |
| 21 |
| 22 class F extends C { |
| 23 String foobar(Z z) { |
| 24 return "FZ"; |
| 25 } |
| 26 |
| 27 String fun<T extends Y>(T t) { |
| 28 if (t is Z) { |
| 29 return this.foobar(t as Z); |
| 30 } |
| 31 return "FY"; |
| 32 } |
| 33 } |
| 34 |
| 35 main() { |
| 36 Y y = new Y(); |
| 37 Z z = new Z(); |
| 38 |
| 39 C c = new C(); |
| 40 F f = new F(); |
| 41 |
| 42 expectTrue(c.fun<Y>(y) == "C"); |
| 43 |
| 44 expectTrue(f.fun<Y>(y) == "FY"); |
| 45 expectTrue(f.fun<Z>(z) == "FZ"); |
| 46 } |
OLD | NEW |