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 | |
5 // Checks that a method with an instantiated return type can override a method | |
6 // with a generic return type. | |
7 | |
8 typedef Collection<K> GetKeysFunctionType<K>(); | |
9 | |
10 class MapBase<K, V> implements Map<K, V> { | |
11 Collection<K> getKeys() { | |
12 throw 'Must be implemented'; | |
13 } | |
14 | |
15 void Tests() { | |
16 Expect.isTrue(this is MapBase<int, int>); | |
17 | |
18 Expect.isTrue(getKeys is GetKeysFunctionType); | |
19 Expect.isTrue(getKeys is GetKeysFunctionType<int>); | |
20 Expect.isTrue(getKeys is !GetKeysFunctionType<String>); | |
21 Expect.isTrue(getKeys is !GetKeysFunctionType<MapBase<int, int>>); | |
22 } | |
23 } | |
24 | |
25 | |
26 class MethodOverrideTest extends MapBase<String, String> { | |
27 Collection<String> getKeys() { | |
28 throw 'Is implemented'; | |
29 } | |
30 | |
31 void Tests() { | |
32 Expect.isTrue(this is MethodOverrideTest); | |
33 Expect.isTrue(this is MapBase<String, String>); | |
34 | |
35 Expect.isTrue(getKeys is GetKeysFunctionType); | |
36 Expect.isTrue(getKeys is GetKeysFunctionType<String>); | |
37 Expect.isTrue(getKeys is !GetKeysFunctionType<int>); | |
38 Expect.isTrue(super.getKeys is GetKeysFunctionType); | |
39 Expect.isTrue(super.getKeys is GetKeysFunctionType<String>); | |
40 Expect.isTrue(super.getKeys is !GetKeysFunctionType<int>); | |
41 } | |
42 } | |
43 | |
44 | |
45 main() { | |
46 // Since method overriding is only checked statically, explicitly check | |
47 // the subtyping relation using a function type alias. | |
48 var x = new MethodOverrideTest(); | |
49 Expect.isTrue(x.getKeys is GetKeysFunctionType<String>); | |
50 | |
51 // Perform a few more tests. | |
52 x.Tests(); | |
53 | |
54 var m = new MapBase<int, int>(); | |
55 Expect.isTrue(m.getKeys is GetKeysFunctionType<int>); | |
56 | |
57 // Perform a few more tests. | |
58 m.Tests(); | |
59 } | |
OLD | NEW |