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 if the type of a parameter of a generic method depends on a type |
| 6 // parameter, the type of the passed argument is checked at runtime if the |
| 7 // receiver is dynamic. The checks should pass if the variables are declared |
| 8 // correctly. |
| 9 |
| 10 library generic_methods_dynamic_test; |
| 11 |
| 12 import "test_base.dart"; |
| 13 |
| 14 class A {} |
| 15 |
| 16 class B {} |
| 17 |
| 18 class C { |
| 19 T foo<T>(T t) => t; |
| 20 List<T> bar<T>(Iterable<T> t) => <T>[t.first]; |
| 21 } |
| 22 |
| 23 main() { |
| 24 B b = new B(); |
| 25 C c = new C(); |
| 26 dynamic obj = c; |
| 27 |
| 28 expectTrue(c.foo<B>(b) == b); |
| 29 expectTrue(obj.foo<B>(b) == b); |
| 30 |
| 31 dynamic x = c.bar<B>(<B>[new B()]); |
| 32 expectTrue(x is List<B>); |
| 33 expectTrue(x.length == 1); |
| 34 |
| 35 dynamic y = obj.bar<B>(<B>[new B()]); |
| 36 expectTrue(y is List<B>); |
| 37 expectTrue(y.length == 1); |
| 38 } |
OLD | NEW |