| 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 a type variable can be used to declare local variables, and that | |
| 6 // these local variables are of correct type. | |
| 7 | |
| 8 library generic_methods_local_variable_declaration_test; | |
| 9 | |
| 10 import "package:expect/expect.dart"; | |
| 11 | |
| 12 class X {} | |
| 13 | |
| 14 abstract class Generator<T> { | |
| 15 T generate(); | |
| 16 } | |
| 17 | |
| 18 class A implements Generator<A> { | |
| 19 generate() { | |
| 20 return new A(); | |
| 21 } | |
| 22 | |
| 23 String toString() => "instance of A"; | |
| 24 } | |
| 25 | |
| 26 class B implements Generator<B> { | |
| 27 generate() { | |
| 28 return new B(); | |
| 29 } | |
| 30 | |
| 31 String toString() => "instance of B"; | |
| 32 } | |
| 33 | |
| 34 String fun<T extends Generator<T>>(T t) { | |
| 35 T another = t.generate(); | |
| 36 String anotherName = "$another"; | |
| 37 | |
| 38 Expect.isTrue(another is T); | |
| 39 Expect.isTrue(another is Generator<T>); | |
| 40 | |
| 41 return anotherName; | |
| 42 } | |
| 43 | |
| 44 main() { | |
| 45 A a = new A(); | |
| 46 B b = new B(); | |
| 47 | |
| 48 Expect.equals(fun<A>(a), "instance of A"); | |
| 49 Expect.equals(fun<B>(b), "instance of B"); | |
| 50 } | |
| OLD | NEW |